LCOV - code coverage report
Current view: top level - framework/source/fwe/helper - titlehelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 281 292 96.2 %
Date: 2012-08-25 Functions: 29 29 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 370 658 56.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <framework/titlehelper.hxx>
      30                 :            : #include <services.h>
      31                 :            : #include <properties.h>
      32                 :            : 
      33                 :            : #include <com/sun/star/frame/UntitledNumbersConst.hpp>
      34                 :            : #include <com/sun/star/frame/XStorable.hpp>
      35                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      36                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      37                 :            : #include <com/sun/star/document/XEventBroadcaster.hpp>
      38                 :            : #include <com/sun/star/beans/XMaterialHolder.hpp>
      39                 :            : 
      40                 :            : #include <unotools/configmgr.hxx>
      41                 :            : #include <unotools/bootstrap.hxx>
      42                 :            : #include <comphelper/sequenceashashmap.hxx>
      43                 :            : #include <rtl/ustrbuf.hxx>
      44                 :            : #include <osl/mutex.hxx>
      45                 :            : #include <tools/urlobj.hxx>
      46                 :            : 
      47                 :            : 
      48                 :            : namespace framework{
      49                 :            : 
      50                 :            : namespace css = ::com::sun::star;
      51                 :            : 
      52                 :            : //-----------------------------------------------
      53                 :       5200 : TitleHelper::TitleHelper(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      54                 :            :     : ::cppu::BaseMutex ()
      55                 :            :     , m_xSMGR           (xSMGR)
      56                 :            :     , m_xOwner          ()
      57                 :            :     , m_xUntitledNumbers()
      58                 :            :     , m_xSubTitle       ()
      59                 :            :     , m_bExternalTitle  (sal_False)
      60                 :            :     , m_sTitle          ()
      61                 :            :     , m_nLeasedNumber   (css::frame::UntitledNumbersConst::INVALID_NUMBER)
      62 [ +  - ][ +  - ]:       5200 :     , m_aListener       (m_aMutex)
         [ +  - ][ +  - ]
                 [ +  - ]
      63                 :            : {
      64                 :       5200 : }
      65                 :            : 
      66                 :            : //-----------------------------------------------
      67 [ +  - ][ +  - ]:       4503 : TitleHelper::~TitleHelper()
         [ +  - ][ +  - ]
                 [ +  - ]
      68                 :            : {
      69         [ -  + ]:       9006 : }
      70                 :            : 
      71                 :            : //-----------------------------------------------
      72                 :       5200 : void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
      73                 :            : {
      74                 :            :     // SYNCHRONIZED ->
      75         [ +  - ]:       5200 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      76                 :            : 
      77         [ +  - ]:       5200 :         m_xOwner = xOwner;
      78                 :            : 
      79         [ +  - ]:       5200 :     aLock.clear ();
      80                 :            :     // <- SYNCHRONIZED
      81                 :            : 
      82         [ +  - ]:       5200 :     css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
      83         [ +  + ]:       5200 :     if (xModel.is ())
      84                 :            :     {
      85         [ +  - ]:       1724 :         impl_startListeningForModel (xModel);
      86                 :            :         return;
      87                 :            :     }
      88                 :            : 
      89         [ +  - ]:       3476 :     css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
      90         [ +  + ]:       3476 :     if (xController.is ())
      91                 :            :     {
      92         [ +  - ]:       1729 :         impl_startListeningForController (xController);
      93                 :            :         return;
      94                 :            :     }
      95                 :            : 
      96         [ +  - ]:       1747 :     css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
      97         [ +  - ]:       1747 :     if (xFrame.is ())
      98                 :            :     {
      99         [ +  - ]:       1747 :         impl_startListeningForFrame (xFrame);
     100                 :            :         return;
     101 [ +  - ][ +  - ]:       5200 :     }
         [ +  - ][ +  - ]
                 [ -  + ]
     102                 :            : }
     103                 :            : 
     104                 :            : //-----------------------------------------------
     105                 :      18676 : ::rtl::OUString SAL_CALL TitleHelper::getTitle()
     106                 :            :     throw (css::uno::RuntimeException)
     107                 :            : {
     108                 :            :     // SYNCHRONIZED ->
     109         [ +  - ]:      18676 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     110                 :            : 
     111                 :            :         // An external title will win always and disable all internal logic about
     112                 :            :         // creating/using a title value.
     113                 :            :         // Even an empty string will be accepted as valid title !
     114         [ +  + ]:      18676 :         if (m_bExternalTitle)
     115                 :          6 :             return m_sTitle;
     116                 :            : 
     117                 :            :         // Title seams to be up-to-date. Return it directly.
     118         [ +  + ]:      18670 :         if (!m_sTitle.isEmpty())
     119                 :      11816 :             return m_sTitle;
     120                 :            : 
     121                 :            :         // Title seams to be unused till now ... do bootstraping
     122         [ +  - ]:       6854 :         impl_updateTitle (true);
     123                 :            : 
     124         [ +  - ]:      18676 :         return m_sTitle;
     125                 :            : 
     126                 :            :     // <- SYNCHRONIZED
     127                 :            : }
     128                 :            : 
     129                 :            : //-----------------------------------------------
     130                 :       3453 : void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
     131                 :            : {
     132                 :            :     // SYNCHRONIZED ->
     133         [ +  - ]:       3453 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     134                 :            : 
     135 [ +  - ][ +  - ]:       3453 :         m_xUntitledNumbers = xNumbers;
     136                 :            : 
     137                 :            :     // <- SYNCHRONIZED
     138                 :       3453 : }
     139                 :            : 
     140                 :            : //-----------------------------------------------
     141                 :          2 : void SAL_CALL TitleHelper::setTitle(const ::rtl::OUString& sTitle)
     142                 :            :     throw (css::uno::RuntimeException)
     143                 :            : {
     144                 :            :     // SYNCHRONIZED ->
     145         [ +  - ]:          2 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     146                 :            : 
     147                 :          2 :         m_bExternalTitle = sal_True;
     148                 :          2 :         m_sTitle         = sTitle;
     149                 :            : 
     150         [ +  - ]:          2 :     aLock.clear ();
     151                 :            :     // <- SYNCHRONIZED
     152                 :            : 
     153 [ +  - ][ +  - ]:          2 :     impl_sendTitleChangedEvent ();
     154                 :          2 : }
     155                 :            : 
     156                 :            : //-----------------------------------------------
     157                 :       5201 : void SAL_CALL TitleHelper::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
     158                 :            :     throw (css::uno::RuntimeException)
     159                 :            : {
     160                 :            :     // container is threadsafe by himself
     161                 :       5201 :     m_aListener.addInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
     162                 :       5201 : }
     163                 :            : 
     164                 :            : //-----------------------------------------------
     165                 :         18 : void SAL_CALL TitleHelper::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
     166                 :            :     throw (css::uno::RuntimeException)
     167                 :            : {
     168                 :            :     // container is threadsafe by himself
     169                 :         18 :     m_aListener.removeInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
     170                 :         18 : }
     171                 :            : 
     172                 :            : //-----------------------------------------------
     173                 :       5986 : void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
     174                 :            :     throw (css::uno::RuntimeException)
     175                 :            : {
     176                 :            :     // SYNCHRONIZED ->
     177         [ +  - ]:       5986 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     178                 :            : 
     179 [ +  - ][ +  - ]:       5986 :         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
     180                 :            : 
     181         [ +  - ]:       5986 :     aLock.clear ();
     182                 :            :     // <- SYNCHRONIZED
     183                 :            : 
     184 [ +  - ][ -  + ]:       5986 :     if (aEvent.Source != xSubTitle)
     185                 :       5969 :         return;
     186                 :            : 
     187 [ +  + ][ -  + ]:       5986 :     impl_updateTitle ();
         [ +  - ][ +  - ]
     188                 :            : }
     189                 :            : 
     190                 :            : //-----------------------------------------------
     191                 :      19618 : void SAL_CALL TitleHelper::notifyEvent(const css::document::EventObject& aEvent)
     192                 :            :     throw (css::uno::RuntimeException)
     193                 :            : {
     194   [ +  +  +  +  :      58791 :     if ( ! aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("OnSaveAsDone"))
           +  + ][ +  + ]
     195                 :      19600 :       && ! aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("OnModeChanged"))
     196                 :      19573 :       && ! aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("OnTitleChanged")))
     197                 :            :         return;
     198                 :            : 
     199                 :            :     // SYNCHRONIZED ->
     200         [ +  - ]:       4388 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     201                 :            : 
     202 [ +  - ][ +  - ]:       4388 :         css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     203                 :            : 
     204         [ +  - ]:       4388 :     aLock.clear ();
     205                 :            :     // <- SYNCHRONIZED
     206                 :            : 
     207 [ +  - ][ +  -  :      17507 :     if (aEvent.Source != xOwner
          +  +  +  +  -  
              + ][ -  + ]
     208                 :            :         || ((aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(
     209                 :       4388 :                  RTL_CONSTASCII_STRINGPARAM("OnModeChanged"))
     210                 :            :              || aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(
     211                 :       4361 :                  RTL_CONSTASCII_STRINGPARAM("OnTitleChanged")))
     212                 :       4370 :             && !xOwner.is()))
     213                 :            :     {
     214                 :            :         return;
     215                 :            :     }
     216                 :            : 
     217 [ +  - ][ -  + ]:      19618 :     impl_updateTitle ();
         [ +  - ][ +  - ]
     218                 :            : }
     219                 :            : 
     220                 :            : //-----------------------------------------------
     221                 :       9591 : void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
     222                 :            :     throw(css::uno::RuntimeException)
     223                 :            : {
     224                 :            :     // SYNCHRONIZED ->
     225         [ +  - ]:       9591 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     226                 :            : 
     227 [ +  - ][ +  - ]:       9591 :         css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     228                 :            : 
     229         [ +  - ]:       9591 :     aLock.clear ();
     230                 :            :     // <- SYNCHRONIZED
     231                 :            : 
     232 [ +  - ][ -  + ]:       9591 :     if (aEvent.Source != xOwner)
     233                 :       9591 :         return;
     234                 :            : 
     235                 :            :     // we are interested on events only, which must trigger a title bar update
     236                 :            :     // because component was changed.
     237 [ +  + ][ +  + ]:       9591 :     if (
                 [ +  + ]
     238                 :            :         (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED  ) ||
     239                 :            :         (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
     240                 :            :         (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
     241                 :            :        )
     242                 :            :     {
     243         [ +  - ]:       3439 :         impl_updateListeningForFrame (xOwner);
     244         [ +  - ]:       9591 :         impl_updateTitle ();
     245 [ -  + ][ +  - ]:       9591 :     }
                 [ +  - ]
     246                 :            : }
     247                 :            : 
     248                 :            : //-----------------------------------------------
     249                 :       3285 : void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
     250                 :            :     throw (css::uno::RuntimeException)
     251                 :            : {
     252                 :            :     // SYNCHRONIZED ->
     253         [ +  - ]:       3285 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     254 [ +  - ][ +  - ]:       3285 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     255 [ +  - ][ +  - ]:       3285 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     256                 :       3285 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     257         [ +  - ]:       3285 :     aLock.clear ();
     258                 :            :     // <- SYNCHRONIZED
     259                 :            : 
     260         [ -  + ]:       3285 :     if ( ! xOwner.is ())
     261                 :            :         return;
     262                 :            : 
     263 [ +  - ][ -  + ]:       3285 :     if (xOwner != aEvent.Source)
     264                 :            :         return;
     265                 :            : 
     266 [ +  + ][ +  + ]:       3285 :     if (
                 [ +  + ]
     267                 :       3285 :         (xNumbers.is ()                                                   ) &&
     268                 :            :         (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     269                 :            :        )
     270 [ +  - ][ +  - ]:       1090 :        xNumbers->releaseNumber (nLeasedNumber);
     271                 :            : 
     272                 :            :     // SYNCHRONIZED ->
     273         [ +  - ]:       3285 :     aLock.reset ();
     274                 :            : 
     275                 :       3285 :          m_sTitle        = ::rtl::OUString ();
     276                 :       3285 :          m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     277                 :            : 
     278         [ +  - ]:       3285 :     aLock.clear ();
     279                 :            :     // <- SYNCHRONIZED
     280                 :            : 
     281 [ +  - ][ -  + ]:       3285 :     impl_sendTitleChangedEvent ();
         [ -  + ][ +  - ]
                 [ +  - ]
     282                 :            : }
     283                 :            : 
     284                 :            : //-----------------------------------------------
     285                 :       7777 : void TitleHelper::impl_sendTitleChangedEvent ()
     286                 :            : {
     287                 :            :     // SYNCHRONIZED ->
     288         [ +  - ]:       7777 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     289                 :            : 
     290 [ +  - ][ +  - ]:       7777 :         css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
     291                 :            : 
     292         [ +  - ]:       7777 :     aLock.clear ();
     293                 :            :     // <- SYNCHRONIZED
     294                 :            : 
     295 [ +  - ][ +  - ]:       7777 :     ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( ::getCppuType( ( const css::uno::Reference< css::frame::XTitleChangeListener >*) NULL ) );
     296         [ +  + ]:       7777 :     if ( ! pContainer)
     297                 :       7777 :         return;
     298                 :            : 
     299         [ +  - ]:       7665 :     ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
     300         [ +  + ]:      15375 :     while ( pIt.hasMoreElements() )
     301                 :            :     {
     302                 :            :         try
     303                 :            :         {
     304 [ +  - ][ +  + ]:       7710 :             ((css::frame::XTitleChangeListener*)pIt.next())->titleChanged( aEvent );
     305                 :            :         }
     306 [ -  + ][ +  - ]:         34 :         catch(const css::uno::Exception&)
     307                 :            :         {
     308         [ -  + ]:         17 :             pIt.remove();
     309                 :            :         }
     310 [ +  - ][ +  - ]:       7777 :     }
         [ +  + ][ +  - ]
                 [ +  + ]
     311                 :            : }
     312                 :            : 
     313                 :            : //-----------------------------------------------
     314                 :      20667 : void TitleHelper::impl_updateTitle (bool init)
     315                 :            : {
     316                 :            :     // SYNCHRONIZED ->
     317         [ +  - ]:      20667 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     318                 :            : 
     319 [ +  - ][ +  - ]:      20667 :         css::uno::Reference< css::frame::XModel >      xModel     (m_xOwner.get(), css::uno::UNO_QUERY);
     320 [ +  - ][ +  - ]:      20667 :         css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
     321 [ +  - ][ +  - ]:      20667 :         css::uno::Reference< css::frame::XFrame >      xFrame     (m_xOwner.get(), css::uno::UNO_QUERY);
     322                 :            : 
     323         [ +  - ]:      20667 :     aLock.clear ();
     324                 :            :     // <- SYNCHRONIZED
     325                 :            : 
     326         [ +  + ]:      20667 :     if (xModel.is ())
     327                 :            :     {
     328         [ +  - ]:       6112 :         impl_updateTitleForModel (xModel, init);
     329                 :            :     }
     330         [ +  + ]:      14555 :     else if (xController.is ())
     331                 :            :     {
     332         [ +  - ]:       7679 :         impl_updateTitleForController (xController, init);
     333                 :            :     }
     334         [ +  + ]:       6876 :     else if (xFrame.is ())
     335                 :            :     {
     336         [ +  + ]:       6875 :         impl_updateTitleForFrame (xFrame, init);
     337         [ +  - ]:      20667 :     }
     338                 :      20650 : }
     339                 :            : 
     340                 :            : //-----------------------------------------------
     341                 :       6112 : void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init)
     342                 :            : {
     343                 :            :     // SYNCHRONIZED ->
     344         [ +  - ]:       6112 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     345                 :            : 
     346                 :            :         // external title wont be updated internaly !
     347                 :            :         // It has to be set from outside new.
     348         [ +  + ]:       6112 :         if (m_bExternalTitle)
     349                 :            :             return;
     350                 :            : 
     351 [ +  - ][ +  - ]:       6102 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     352 [ +  - ][ +  - ]:       6102 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     353                 :       6102 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     354                 :            : 
     355         [ +  - ]:       6102 :     aLock.clear ();
     356                 :            :     // <- SYNCHRONIZED
     357                 :            : 
     358 [ -  + ][ +  -  :      18306 :     if (
             +  -  -  + ]
     359                 :       6102 :         ( ! xOwner.is    ()) ||
     360                 :       6102 :         ( ! xNumbers.is  ()) ||
     361                 :       6102 :         ( ! xModel.is    ())
     362                 :            :        )
     363                 :            :         return;
     364                 :            : 
     365                 :       6102 :     ::rtl::OUString sTitle;
     366                 :       6102 :     ::rtl::OUString sURL  ;
     367                 :            : 
     368         [ +  - ]:       6102 :     css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
     369         [ +  - ]:       6102 :     if (xURLProvider.is())
     370 [ +  - ][ +  - ]:       6102 :         sURL = xURLProvider->getLocation ();
     371                 :            : 
     372         [ +  + ]:       6102 :     if (!sURL.isEmpty())
     373                 :            :     {
     374         [ +  - ]:       1325 :         sTitle = impl_convertURL2Title(sURL);
     375         [ +  + ]:       1325 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     376 [ +  - ][ +  - ]:         10 :             xNumbers->releaseNumber (nLeasedNumber);
     377                 :       1325 :         nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     378                 :            :     }
     379                 :            :     else
     380                 :            :     {
     381         [ +  + ]:       4777 :         if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     382 [ +  - ][ +  - ]:       1104 :             nLeasedNumber = xNumbers->leaseNumber (xOwner);
     383                 :            : 
     384                 :       4777 :         ::rtl::OUStringBuffer sNewTitle(256);
     385 [ +  - ][ +  - ]:       4777 :         sNewTitle.append (xNumbers->getUntitledPrefix ());
                 [ +  - ]
     386         [ +  - ]:       4777 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     387         [ +  - ]:       4777 :             sNewTitle.append ((::sal_Int32)nLeasedNumber);
     388                 :            :         else
     389         [ #  # ]:          0 :             sNewTitle.appendAscii ("?");
     390                 :            : 
     391         [ +  - ]:       4777 :         sTitle = sNewTitle.makeStringAndClear ();
     392                 :            :     }
     393                 :            : 
     394                 :            :     // SYNCHRONIZED ->
     395         [ +  - ]:       6102 :     aLock.reset ();
     396                 :            : 
     397                 :            :     // WORKAROUND: the notification is currently sent always,
     398                 :            :     //             can be changed after shared mode is supported per UNO API
     399                 :       6102 :     sal_Bool bChanged        = !init; // && m_sTitle != sTitle
     400                 :            : 
     401                 :       6102 :              m_sTitle        = sTitle;
     402                 :       6102 :              m_nLeasedNumber = nLeasedNumber;
     403                 :            : 
     404         [ +  - ]:       6102 :     aLock.clear ();
     405                 :            :     // <- SYNCHRONIZED
     406                 :            : 
     407         [ +  + ]:       6102 :     if (bChanged)
     408 [ +  - ][ -  + ]:       6112 :         impl_sendTitleChangedEvent ();
         [ -  + ][ +  - ]
                 [ +  + ]
     409                 :            : }
     410                 :            : 
     411                 :            : //-----------------------------------------------
     412                 :       7679 : void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init)
     413                 :            : {
     414                 :            :     // SYNCHRONIZED ->
     415         [ +  - ]:       7679 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     416                 :            : 
     417                 :            :         // external title wont be updated internaly !
     418                 :            :         // It has to be set from outside new.
     419         [ -  + ]:       7679 :         if (m_bExternalTitle)
     420                 :            :             return;
     421                 :            : 
     422 [ +  - ][ +  - ]:       7679 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     423 [ +  - ][ +  - ]:       7679 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     424                 :       7679 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     425                 :            : 
     426         [ +  - ]:       7679 :     aLock.clear ();
     427                 :            :     // <- SYNCHRONIZED
     428                 :            : 
     429 [ +  + ][ +  -  :      23033 :     if (
             +  +  -  + ]
     430                 :       7679 :         ( ! xOwner.is      ()) ||
     431                 :       7679 :         ( ! xNumbers.is    ()) ||
     432                 :       7675 :         ( ! xController.is ())
     433                 :            :        )
     434                 :            :         return;
     435                 :            : 
     436                 :       7675 :     ::rtl::OUStringBuffer sTitle(256);
     437                 :            : 
     438         [ +  + ]:       7675 :     if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     439 [ +  - ][ +  - ]:       1727 :         nLeasedNumber = xNumbers->leaseNumber (xOwner);
     440                 :            : 
     441 [ +  - ][ +  - ]:       7675 :     css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
                 [ +  - ]
     442         [ +  + ]:       7675 :     if (!xModelTitle.is ())
     443         [ +  - ]:       1661 :         xModelTitle.set(xController, css::uno::UNO_QUERY);
     444         [ +  - ]:       7675 :     if (xModelTitle.is ())
     445                 :            :     {
     446 [ +  - ][ +  - ]:       7675 :         sTitle.append      (xModelTitle->getTitle ());
                 [ +  - ]
     447         [ +  + ]:       7675 :         if ( nLeasedNumber > 1 )
     448                 :            :         {
     449         [ +  - ]:         63 :             sTitle.appendAscii (" : ");
     450         [ +  - ]:         63 :             sTitle.append      ((::sal_Int32)nLeasedNumber);
     451                 :            :         }
     452                 :            :     }
     453                 :            :     else
     454                 :            :     {
     455 [ #  # ][ #  # ]:          0 :         sTitle.append (xNumbers->getUntitledPrefix ());
                 [ #  # ]
     456         [ #  # ]:          0 :         if ( nLeasedNumber > 1 )
     457                 :            :         {
     458         [ #  # ]:          0 :             sTitle.append ((::sal_Int32)nLeasedNumber  );
     459                 :            :         }
     460                 :            :     }
     461                 :            : 
     462                 :            :     // SYNCHRONIZED ->
     463         [ +  - ]:       7675 :     aLock.reset ();
     464                 :            : 
     465         [ +  - ]:       7675 :         ::rtl::OUString sNewTitle       = sTitle.makeStringAndClear ();
     466 [ +  + ][ +  + ]:       7675 :         sal_Bool        bChanged        = !init && m_sTitle != sNewTitle;
     467                 :       7675 :                         m_sTitle        = sNewTitle;
     468                 :       7675 :                         m_nLeasedNumber = nLeasedNumber;
     469                 :            : 
     470         [ +  - ]:       7675 :     aLock.clear ();
     471                 :            :     // <- SYNCHRONIZED
     472                 :            : 
     473         [ +  + ]:       7675 :     if (bChanged)
     474 [ +  - ][ +  + ]:       7679 :         impl_sendTitleChangedEvent ();
         [ +  + ][ +  - ]
                 [ +  + ]
     475                 :            : }
     476                 :            : 
     477                 :            : //-----------------------------------------------
     478                 :       6875 : void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init)
     479                 :            : {
     480         [ +  - ]:       6875 :     if ( ! xFrame.is ())
     481                 :            :         return;
     482                 :            : 
     483                 :            :     // SYNCHRONIZED ->
     484         [ +  - ]:       6875 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     485                 :            : 
     486                 :            :         // external title wont be updated internaly !
     487                 :            :         // It has to be set from outside new.
     488         [ -  + ]:       6875 :         if (m_bExternalTitle)
     489                 :            :             return;
     490                 :            : 
     491         [ +  - ]:       6875 :     aLock.clear ();
     492                 :            :     // <- SYNCHRONIZED
     493                 :            : 
     494                 :       6875 :     css::uno::Reference< css::uno::XInterface > xComponent;
     495 [ +  - ][ +  - ]:       6875 :     xComponent = xFrame->getController ();
                 [ +  - ]
     496         [ +  + ]:       6875 :     if ( ! xComponent.is ())
     497 [ +  - ][ +  + ]:       1671 :         xComponent = xFrame->getComponentWindow ();
                 [ +  - ]
     498                 :            : 
     499                 :       6858 :     ::rtl::OUStringBuffer sTitle (256);
     500                 :            : 
     501         [ +  - ]:       6858 :     impl_appendComponentTitle   (sTitle, xComponent);
     502         [ +  - ]:       6858 :     impl_appendProductName      (sTitle);
     503         [ +  - ]:       6858 :     impl_appendModuleName       (sTitle);
     504         [ +  - ]:       6858 :     impl_appendProductExtension (sTitle);
     505         [ +  - ]:       6858 :     impl_appendDebugVersion     (sTitle);
     506                 :            : 
     507                 :            :     // SYNCHRONIZED ->
     508         [ +  - ]:       6858 :     aLock.reset ();
     509                 :            : 
     510         [ +  - ]:       6858 :         ::rtl::OUString sNewTitle = sTitle.makeStringAndClear ();
     511 [ +  + ][ +  + ]:       6858 :         sal_Bool        bChanged  = !init && m_sTitle != sNewTitle;
     512                 :       6858 :                         m_sTitle  = sNewTitle;
     513                 :            : 
     514         [ +  - ]:       6858 :     aLock.clear ();
     515                 :            :     // <- SYNCHRONIZED
     516                 :            : 
     517         [ +  + ]:       6858 :     if (bChanged)
     518 [ +  - ][ +  - ]:       6875 :         impl_sendTitleChangedEvent ();
                 [ +  - ]
     519                 :            : }
     520                 :            : 
     521                 :            : //*****************************************************************************************************************
     522                 :       6858 : void TitleHelper::impl_appendComponentTitle (      ::rtl::OUStringBuffer&                       sTitle    ,
     523                 :            :                                              const css::uno::Reference< css::uno::XInterface >& xComponent)
     524                 :            : {
     525         [ +  - ]:       6858 :     css::uno::Reference< css::frame::XTitle > xTitle(xComponent, css::uno::UNO_QUERY);
     526                 :            : 
     527                 :            :     // Note: Title has to be used (even if it's empty) if the right interface is supported.
     528         [ +  + ]:       6858 :     if (xTitle.is ())
     529 [ +  - ][ +  - ]:       6858 :         sTitle.append (xTitle->getTitle ());
                 [ +  - ]
     530                 :       6858 : }
     531                 :            : 
     532                 :            : //*****************************************************************************************************************
     533                 :       6858 : void TitleHelper::impl_appendProductName (::rtl::OUStringBuffer& sTitle)
     534                 :            : {
     535         [ +  - ]:       6858 :     rtl::OUString name(utl::ConfigManager::getProductName());
     536         [ +  - ]:       6858 :     if (!name.isEmpty())
     537                 :            :     {
     538         [ +  + ]:       6858 :         if (sTitle.getLength() != 0)
     539         [ +  - ]:       5096 :             sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM(" - "));
     540         [ +  - ]:       6858 :         sTitle.append(name);
     541                 :       6858 :     }
     542                 :       6858 : }
     543                 :            : 
     544                 :            : //*****************************************************************************************************************
     545                 :       6858 : void TitleHelper::impl_appendProductExtension (::rtl::OUStringBuffer& sTitle)
     546                 :            : {
     547         [ +  - ]:       6858 :     rtl::OUString ext(utl::ConfigManager::getProductExtension());
     548         [ +  + ]:       6858 :     if (!ext.isEmpty())
     549                 :            :     {
     550         [ +  - ]:       2074 :         sTitle.append(' ');
     551         [ +  - ]:       2074 :         sTitle.append(ext);
     552                 :       6858 :     }
     553                 :       6858 : }
     554                 :            : 
     555                 :            : //*****************************************************************************************************************
     556                 :       6858 : void TitleHelper::impl_appendModuleName (::rtl::OUStringBuffer& sTitle)
     557                 :            : {
     558                 :            :     // SYNCHRONIZED ->
     559         [ +  - ]:       6858 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     560                 :            : 
     561         [ +  - ]:       6858 :         css::uno::Reference< css::uno::XInterface >            xOwner = m_xOwner.get();
     562                 :       6858 :         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     563                 :            : 
     564         [ +  - ]:       6858 :     aLock.clear ();
     565                 :            :     // <- SYNCHRONIZED
     566                 :            : 
     567                 :            :     try
     568                 :            :     {
     569                 :            :         css::uno::Reference< css::frame::XModuleManager > xModuleManager(
     570         [ +  - ]:       6858 :             xSMGR->createInstance(SERVICENAME_MODULEMANAGER),
     571 [ +  - ][ +  - ]:       6858 :             css::uno::UNO_QUERY_THROW);
                 [ +  - ]
     572                 :            : 
     573                 :            :         css::uno::Reference< css::container::XNameAccess > xConfig(
     574                 :            :             xModuleManager,
     575         [ +  - ]:       6858 :             css::uno::UNO_QUERY_THROW);
     576                 :            : 
     577 [ +  - ][ +  + ]:       6858 :         const ::rtl::OUString                 sID     = xModuleManager->identify(xOwner);
     578 [ +  - ][ +  - ]:       5172 :               ::comphelper::SequenceAsHashMap lProps  = xConfig->getByName (sID);
                 [ +  - ]
     579 [ +  - ][ +  - ]:       5172 :         const ::rtl::OUString                 sUIName = lProps.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_UINAME, ::rtl::OUString());
     580                 :            : 
     581                 :            :         // An UIname property is an optional value !
     582                 :            :         // So please add it to the title in case it does realy exists only.
     583         [ +  + ]:       5172 :         if (!sUIName.isEmpty())
     584                 :            :         {
     585         [ +  - ]:       5168 :             sTitle.appendAscii (" "    );
     586         [ +  - ]:       5168 :             sTitle.append      (sUIName);
     587 [ +  - ][ -  + ]:       6858 :         }
     588                 :            :     }
     589         [ +  - ]:       1686 :     catch(const css::uno::Exception&)
     590         [ +  - ]:       6858 :     {}
     591                 :       6858 : }
     592                 :            : 
     593                 :            : //*****************************************************************************************************************
     594                 :            : #ifdef DBG_UTIL
     595                 :            : void TitleHelper::impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle)
     596                 :            : {
     597                 :            :     ::rtl::OUString sDefault(RTL_CONSTASCII_USTRINGPARAM("development"));
     598                 :            :     ::rtl::OUString sVersion = ::utl::Bootstrap::getProductSource(sDefault);
     599                 :            :     sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ["));
     600                 :            :     sTitle.append(sVersion);
     601                 :            :     sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM("]"));
     602                 :            : }
     603                 :            : #else
     604                 :       6858 : void TitleHelper::impl_appendDebugVersion (::rtl::OUStringBuffer&)
     605                 :            : {
     606                 :       6858 : }
     607                 :            : #endif
     608                 :            : 
     609                 :            : //-----------------------------------------------
     610                 :       1724 : void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
     611                 :            : {
     612         [ +  - ]:       1724 :     css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
     613         [ -  + ]:       1724 :     if ( ! xBroadcaster.is ())
     614                 :       1724 :         return;
     615                 :            : 
     616 [ +  - ][ +  - ]:       1724 :     xBroadcaster->addEventListener (static_cast< css::document::XEventListener* >(this));
         [ +  - ][ +  - ]
     617                 :            : }
     618                 :            : 
     619                 :            : //-----------------------------------------------
     620                 :       1729 : void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
     621                 :            : {
     622 [ +  - ][ +  - ]:       1729 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
                 [ +  - ]
     623         [ +  - ]:       1729 :     impl_setSubTitle (xSubTitle);
     624                 :       1729 : }
     625                 :            : 
     626                 :            : //-----------------------------------------------
     627                 :       1747 : void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     628                 :            : {
     629         [ +  - ]:       1747 :     xFrame->addFrameActionListener(this  );
     630                 :       1747 :     impl_updateListeningForFrame  (xFrame);
     631                 :       1747 : }
     632                 :            : 
     633                 :            : //-----------------------------------------------
     634                 :       5186 : void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     635                 :            : {
     636 [ +  - ][ +  - ]:       5186 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
                 [ +  - ]
     637         [ +  - ]:       5186 :     impl_setSubTitle (xSubTitle);
     638                 :       5186 : }
     639                 :            : 
     640                 :            : //-----------------------------------------------
     641                 :       6915 : void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
     642                 :            : {
     643                 :            :     // SYNCHRONIZED ->
     644         [ +  - ]:       6915 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     645                 :            : 
     646                 :            :         // ignore duplicate calls. Makes outside using of this helper more easy :-)
     647 [ +  - ][ +  - ]:       6915 :         css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
     648 [ +  + ][ +  - ]:       6915 :         if (xOldSubTitle == xSubTitle)
     649                 :       6915 :             return;
     650                 :            : 
     651         [ +  - ]:       3458 :         m_xSubTitle = xSubTitle;
     652                 :            : 
     653         [ +  - ]:       3458 :     aLock.clear ();
     654                 :            :     // <- SYNCHRONIZED
     655                 :            : 
     656         [ +  - ]:       3458 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle                                          , css::uno::UNO_QUERY      );
     657         [ +  - ]:       3458 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle                                             , css::uno::UNO_QUERY      );
     658         [ +  - ]:       3458 :     css::uno::Reference< css::frame::XTitleChangeListener >    xThis          (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
     659                 :            : 
     660         [ +  + ]:       3458 :     if (xOldBroadcaster.is())
     661 [ +  - ][ +  - ]:         18 :         xOldBroadcaster->removeTitleChangeListener (xThis);
     662                 :            : 
     663         [ +  + ]:       3458 :     if (xNewBroadcaster.is())
     664 [ +  - ][ +  - ]:       6915 :         xNewBroadcaster->addTitleChangeListener (xThis);
         [ +  + ][ +  - ]
                 [ +  + ]
     665                 :            : }
     666                 :            : 
     667                 :            : //-----------------------------------------------
     668                 :       1325 : ::rtl::OUString TitleHelper::impl_convertURL2Title(const ::rtl::OUString& sURL)
     669                 :            : {
     670         [ +  - ]:       1325 :     INetURLObject   aURL (sURL);
     671                 :       1325 :     ::rtl::OUString sTitle;
     672                 :            : 
     673         [ +  - ]:       1325 :     if (aURL.GetProtocol() == INET_PROT_FILE)
     674                 :            :     {
     675 [ +  - ][ -  + ]:       1325 :         if (aURL.HasMark())
     676 [ #  # ][ #  # ]:          0 :             aURL = INetURLObject(aURL.GetURLNoMark());
         [ #  # ][ #  # ]
     677                 :            : 
     678         [ +  - ]:       1325 :         sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
     679                 :            :     }
     680                 :            :     else
     681                 :            :     {
     682 [ #  # ][ #  # ]:          0 :         if (aURL.hasExtension(INetURLObject::LAST_SEGMENT))
     683         [ #  # ]:          0 :             sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
     684                 :            : 
     685         [ #  # ]:          0 :         if ( sTitle.isEmpty() )
     686         [ #  # ]:          0 :             sTitle = aURL.GetHostPort(INetURLObject::DECODE_WITH_CHARSET);
     687                 :            : 
     688         [ #  # ]:          0 :         if ( sTitle.isEmpty() )
     689         [ #  # ]:          0 :             sTitle = aURL.GetURLNoPass(INetURLObject::DECODE_WITH_CHARSET);
     690                 :            :     }
     691                 :            : 
     692         [ +  - ]:       1325 :     return sTitle;
     693                 :            : }
     694                 :            : 
     695                 :            : } // namespace framework
     696                 :            : 
     697                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10