LCOV - code coverage report
Current view: top level - framework/source/uielement - toolbarwrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 105 144 72.9 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 105 282 37.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 <uielement/toolbarwrapper.hxx>
      30                 :            : #include <threadhelp/resetableguard.hxx>
      31                 :            : #include <framework/actiontriggerhelper.hxx>
      32                 :            : #include <uielement/constitemcontainer.hxx>
      33                 :            : #include <uielement/rootitemcontainer.hxx>
      34                 :            : #include <uielement/toolbarmanager.hxx>
      35                 :            : 
      36                 :            : #include <uielement/toolbar.hxx>
      37                 :            : 
      38                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      39                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      40                 :            : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
      41                 :            : #include <com/sun/star/awt/XMenuBar.hpp>
      42                 :            : #include <com/sun/star/container/XIndexContainer.hpp>
      43                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      44                 :            : #include <com/sun/star/ui/UIElementType.hpp>
      45                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      46                 :            : 
      47                 :            : #include <toolkit/unohlp.hxx>
      48                 :            : #include <toolkit/awt/vclxwindow.hxx>
      49                 :            : #include <comphelper/processfactory.hxx>
      50                 :            : 
      51                 :            : #include <svtools/miscopt.hxx>
      52                 :            : #include <vcl/svapp.hxx>
      53                 :            : #include <vcl/toolbox.hxx>
      54                 :            : #include <rtl/logfile.hxx>
      55                 :            : 
      56                 :            : using namespace com::sun::star;
      57                 :            : using namespace com::sun::star::uno;
      58                 :            : using namespace com::sun::star::beans;
      59                 :            : using namespace com::sun::star::frame;
      60                 :            : using namespace com::sun::star::lang;
      61                 :            : using namespace com::sun::star::container;
      62                 :            : using namespace com::sun::star::awt;
      63                 :            : using namespace ::com::sun::star::ui;
      64                 :            : 
      65                 :            : namespace framework
      66                 :            : {
      67                 :            : 
      68                 :       3709 : ToolBarWrapper::ToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
      69         [ +  - ]:       3709 :     UIConfigElementWrapperBase( UIElementType::TOOLBAR,xServiceManager )
      70                 :            : {
      71                 :       3709 : }
      72                 :            : 
      73         [ +  - ]:       3527 : ToolBarWrapper::~ToolBarWrapper()
      74                 :            : {
      75         [ -  + ]:       7054 : }
      76                 :            : 
      77                 :            : // XInterface
      78                 :     139729 : void SAL_CALL ToolBarWrapper::acquire() throw()
      79                 :            : {
      80                 :     139729 :     UIConfigElementWrapperBase::acquire();
      81                 :     139729 : }
      82                 :            : 
      83                 :     139547 : void SAL_CALL ToolBarWrapper::release() throw()
      84                 :            : {
      85                 :     139547 :     UIConfigElementWrapperBase::release();
      86                 :     139547 : }
      87                 :            : 
      88                 :      25764 : uno::Any SAL_CALL ToolBarWrapper::queryInterface( const uno::Type & rType )
      89                 :            : throw( ::com::sun::star::uno::RuntimeException )
      90                 :            : {
      91                 :            :     Any a = ::cppu::queryInterface(
      92                 :            :                 rType ,
      93         [ +  - ]:      25764 :                 (static_cast< ::com::sun::star::ui::XUIFunctionListener* >(this)) );
      94                 :            : 
      95         [ +  + ]:      25764 :     if( a.hasValue() )
      96                 :          4 :         return a;
      97                 :            : 
      98         [ +  - ]:      25764 :     return UIConfigElementWrapperBase::queryInterface( rType );
      99                 :            : }
     100                 :            : 
     101                 :            : // XComponent
     102                 :       3527 : void SAL_CALL ToolBarWrapper::dispose() throw ( RuntimeException )
     103                 :            : {
     104         [ +  - ]:       3527 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
     105                 :            : 
     106                 :            :     {
     107         [ +  - ]:       3527 :         ResetableGuard aLock( m_aLock );
     108         [ -  + ]:       3527 :         if ( m_bDisposed )
     109 [ +  - ][ +  - ]:       7054 :             return;
     110                 :            :     }
     111                 :            : 
     112         [ +  - ]:       3527 :     com::sun::star::lang::EventObject aEvent( xThis );
     113         [ +  - ]:       3527 :     m_aListenerContainer.disposeAndClear( aEvent );
     114                 :            : 
     115         [ +  - ]:       3527 :     ResetableGuard aLock( m_aLock );
     116                 :            : 
     117         [ +  - ]:       3527 :     if ( m_xToolBarManager.is() )
     118 [ +  - ][ +  - ]:       3527 :         m_xToolBarManager->dispose();
     119                 :       3527 :     m_xToolBarManager.clear();
     120                 :       3527 :     m_xConfigSource.clear();
     121                 :       3527 :     m_xConfigData.clear();
     122                 :       3527 :     m_xToolBarWindow.clear();
     123                 :            : 
     124 [ +  - ][ +  - ]:       3527 :     m_bDisposed = sal_True;
                 [ +  - ]
     125                 :            : }
     126                 :            : 
     127                 :            : // XInitialization
     128                 :       3709 : void SAL_CALL ToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
     129                 :            : {
     130         [ +  - ]:       3709 :     ResetableGuard aLock( m_aLock );
     131                 :            : 
     132         [ -  + ]:       3709 :     if ( m_bDisposed )
     133         [ #  # ]:          0 :         throw DisposedException();
     134                 :            : 
     135         [ +  - ]:       3709 :     if ( !m_bInitialized )
     136                 :            :     {
     137         [ +  - ]:       3709 :         UIConfigElementWrapperBase::initialize( aArguments );
     138                 :            : 
     139                 :       3709 :         sal_Bool bPopupMode( sal_False );
     140         [ +  - ]:      22254 :         for ( sal_Int32 i = 0; i < aArguments.getLength(); i++ )
     141                 :            :         {
     142                 :      18545 :             PropertyValue aPropValue;
     143 [ +  - ][ +  - ]:      18545 :             if ( aArguments[i] >>= aPropValue )
     144                 :            :             {
     145         [ +  + ]:      18545 :                 if ( aPropValue.Name.equalsAsciiL( "PopupMode", 9 ))
     146                 :            :                 {
     147                 :      18545 :                     aPropValue.Value >>= bPopupMode;
     148                 :            :                     break;
     149                 :            :                 }
     150                 :            :             }
     151         [ +  + ]:      18545 :         }
     152                 :            : 
     153         [ +  - ]:       3709 :         Reference< XFrame > xFrame( m_xWeakFrame );
     154 [ +  - ][ +  - ]:       3709 :         if ( xFrame.is() && m_xConfigSource.is() )
                 [ +  - ]
     155                 :            :         {
     156                 :            :             // Create VCL based toolbar which will be filled with settings data
     157                 :       3709 :             ToolBar* pToolBar = 0;
     158                 :       3709 :             ToolBarManager* pToolBarManager = 0;
     159                 :            :             {
     160         [ +  - ]:       3709 :                 SolarMutexGuard aSolarMutexGuard;
     161 [ +  - ][ +  - ]:       3709 :                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
                 [ +  - ]
     162         [ +  - ]:       3709 :                 if ( pWindow )
     163                 :            :                 {
     164                 :       3709 :                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
     165                 :            : 
     166 [ +  - ][ +  - ]:       3709 :                     pToolBar = new ToolBar( pWindow, nStyles );
     167 [ +  - ][ +  - ]:       3709 :                     m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
     168         [ +  - ]:       3709 :                     pToolBarManager = new ToolBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pToolBar );
     169         [ +  - ]:       3709 :                     pToolBar->SetToolBarManager( pToolBarManager );
     170 [ +  - ][ +  - ]:       3709 :                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
                 [ +  - ]
     171         [ +  - ]:       3709 :                     pToolBar->WillUsePopupMode( bPopupMode );
     172         [ +  - ]:       3709 :                 }
     173                 :            :             }
     174                 :            : 
     175                 :            :             try
     176                 :            :             {
     177 [ +  - ][ +  + ]:       3709 :                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
                 [ +  - ]
     178 [ +  - ][ +  - ]:       2548 :                 if ( m_xConfigData.is() && pToolBar && pToolBarManager )
         [ +  - ][ +  - ]
     179                 :            :                 {
     180                 :            :                     // Fill toolbar with container contents
     181         [ +  - ]:       2548 :                     pToolBarManager->FillToolbar( m_xConfigData );
     182 [ +  - ][ +  - ]:       2548 :                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
         [ +  - ][ +  - ]
     183         [ +  - ]:       2548 :                     pToolBar->EnableCustomize( sal_True );
     184         [ +  - ]:       2548 :                     ::Size aActSize( pToolBar->GetSizePixel() );
     185         [ +  - ]:       2548 :                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
     186                 :       2548 :                     aSize.Width() = aActSize.Width();
     187         [ +  - ]:       2548 :                     pToolBar->SetOutputSizePixel( aSize );
     188                 :            :                 }
     189                 :            :             }
     190 [ -  + ][ +  - ]:       2322 :             catch ( const NoSuchElementException& )
     191                 :            :             {
     192                 :            :                 // No settings in our configuration manager. This means we are
     193                 :            :                 // a transient toolbar which has no persistent settings.
     194                 :       1161 :                 m_bPersistent = sal_False;
     195 [ +  - ][ +  - ]:       1161 :                 if ( pToolBar && pToolBarManager )
     196                 :            :                 {
     197 [ -  + ][ -  + ]:       1161 :                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
         [ -  + ][ -  + ]
     198         [ -  + ]:       1161 :                     pToolBar->EnableCustomize( sal_True );
     199         [ -  + ]:       1161 :                     ::Size aActSize( pToolBar->GetSizePixel() );
     200         [ -  + ]:       1161 :                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
     201                 :       1161 :                     aSize.Width() = aActSize.Width();
     202         [ -  + ]:       1161 :                     pToolBar->SetOutputSizePixel( aSize );
     203                 :            :                 }
     204                 :            :             }
     205                 :       3709 :         }
     206         [ +  - ]:       3709 :     }
     207                 :       3709 : }
     208                 :            : 
     209                 :            : // XEventListener
     210                 :          0 : void SAL_CALL ToolBarWrapper::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
     211                 :            : {
     212                 :            :     // nothing todo
     213                 :          0 : }
     214                 :            : 
     215                 :            : // XUpdatable
     216                 :          0 : void SAL_CALL ToolBarWrapper::update() throw (::com::sun::star::uno::RuntimeException)
     217                 :            : {
     218         [ #  # ]:          0 :     ResetableGuard aLock( m_aLock );
     219                 :            : 
     220         [ #  # ]:          0 :     if ( m_bDisposed )
     221         [ #  # ]:          0 :         throw DisposedException();
     222                 :            : 
     223 [ #  # ][ #  # ]:          0 :     ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     224         [ #  # ]:          0 :     if ( pToolBarManager )
     225 [ #  # ][ #  # ]:          0 :         pToolBarManager->CheckAndUpdateImages();
     226                 :          0 : }
     227                 :            : 
     228                 :            : // XUIElementSettings
     229                 :          0 : void SAL_CALL ToolBarWrapper::updateSettings() throw (::com::sun::star::uno::RuntimeException)
     230                 :            : {
     231         [ #  # ]:          0 :     ResetableGuard aLock( m_aLock );
     232                 :            : 
     233         [ #  # ]:          0 :     if ( m_bDisposed )
     234         [ #  # ]:          0 :         throw DisposedException();
     235                 :            : 
     236         [ #  # ]:          0 :     if ( m_xToolBarManager.is() )
     237                 :            :     {
     238 [ #  # ][ #  # ]:          0 :         if ( m_xConfigSource.is() && m_bPersistent )
                 [ #  # ]
     239                 :            :         {
     240                 :            :             try
     241                 :            :             {
     242 [ #  # ][ #  # ]:          0 :                 ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     243                 :            : 
     244 [ #  # ][ #  # ]:          0 :                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
         [ #  # ][ #  # ]
     245         [ #  # ]:          0 :                 if ( m_xConfigData.is() )
     246         [ #  # ]:          0 :                     pToolBarManager->FillToolbar( m_xConfigData );
     247                 :            :             }
     248         [ #  # ]:          0 :             catch ( const NoSuchElementException& )
     249                 :            :             {
     250                 :            :             }
     251                 :            :         }
     252                 :          0 :         else if ( !m_bPersistent )
     253                 :            :         {
     254                 :            :             // Transient toolbar: do nothing
     255                 :            :         }
     256         [ #  # ]:          0 :     }
     257                 :          0 : }
     258                 :            : 
     259                 :          0 : void ToolBarWrapper::impl_fillNewData()
     260                 :            : {
     261                 :            :     // Transient toolbar => Fill toolbar with new data
     262         [ #  # ]:          0 :     ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     263         [ #  # ]:          0 :     if ( pToolBarManager )
     264                 :          0 :         pToolBarManager->FillToolbar( m_xConfigData );
     265                 :          0 : }
     266                 :            : 
     267                 :            : // XUIElement interface
     268                 :      37705 : Reference< XInterface > SAL_CALL ToolBarWrapper::getRealInterface(  ) throw (::com::sun::star::uno::RuntimeException)
     269                 :            : {
     270         [ +  - ]:      37705 :     ResetableGuard aLock( m_aLock );
     271                 :            : 
     272         [ +  - ]:      37705 :     if ( m_xToolBarManager.is() )
     273                 :            :     {
     274 [ +  - ][ +  - ]:      37705 :         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     275         [ +  - ]:      37705 :         if ( pToolBarManager )
     276                 :            :         {
     277         [ +  - ]:      37705 :             Window* pWindow = (Window *)pToolBarManager->GetToolBar();
     278 [ +  - ][ +  - ]:      37705 :             return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
     279                 :            :         }
     280                 :            :     }
     281                 :            : 
     282         [ +  - ]:      37705 :     return Reference< XInterface >();
     283                 :            : }
     284                 :            : 
     285                 :            : //XUIFunctionExecute
     286                 :          4 : void SAL_CALL ToolBarWrapper::functionExecute(
     287                 :            :     const ::rtl::OUString& aUIElementName,
     288                 :            :     const ::rtl::OUString& aCommand )
     289                 :            : throw (::com::sun::star::uno::RuntimeException)
     290                 :            : {
     291         [ +  - ]:          4 :     ResetableGuard aLock( m_aLock );
     292                 :            : 
     293         [ +  - ]:          4 :     if ( m_xToolBarManager.is() )
     294                 :            :     {
     295 [ +  - ][ +  - ]:          4 :         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     296         [ +  - ]:          4 :         if ( pToolBarManager )
     297         [ +  - ]:          4 :             pToolBarManager->notifyRegisteredControllers( aUIElementName, aCommand );
     298         [ +  - ]:          4 :     }
     299                 :          4 : }
     300                 :            : 
     301                 :      14836 : void SAL_CALL ToolBarWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any&  aValue ) throw( com::sun::star::uno::Exception )
     302                 :            : {
     303         [ +  - ]:      14836 :     ResetableGuard aLock( m_aLock );
     304                 :      14836 :     sal_Bool bNoClose( m_bNoClose );
     305         [ +  - ]:      14836 :     aLock.unlock();
     306                 :            : 
     307         [ +  - ]:      14836 :     UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
     308                 :            : 
     309         [ +  - ]:      14836 :     aLock.lock();
     310                 :            : 
     311                 :      14836 :     sal_Bool bNewNoClose( m_bNoClose );
     312 [ -  + ][ #  # ]:      14836 :     if ( m_xToolBarManager.is() && !m_bDisposed && ( bNewNoClose != bNoClose ))
         [ #  # ][ -  + ]
     313                 :            :     {
     314 [ #  # ][ #  # ]:          0 :         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     315         [ #  # ]:          0 :         if ( pToolBarManager )
     316                 :            :         {
     317         [ #  # ]:          0 :             ToolBox* pToolBox = pToolBarManager->GetToolBar();
     318         [ #  # ]:          0 :             if ( pToolBox )
     319                 :            :             {
     320         [ #  # ]:          0 :                 if ( bNewNoClose )
     321                 :            :                 {
     322                 :          0 :                     pToolBox->SetStyle( pToolBox->GetStyle() & ~WB_CLOSEABLE );
     323 [ #  # ][ #  # ]:          0 :                     pToolBox->SetFloatStyle( pToolBox->GetFloatStyle() & ~WB_CLOSEABLE );
     324                 :            :                 }
     325                 :            :                 else
     326                 :            :                 {
     327                 :          0 :                     pToolBox->SetStyle( pToolBox->GetStyle() | WB_CLOSEABLE );
     328 [ #  # ][ #  # ]:          0 :                     pToolBox->SetFloatStyle( pToolBox->GetFloatStyle() | WB_CLOSEABLE );
     329                 :            :                 }
     330                 :            :             }
     331                 :            :         }
     332         [ +  - ]:      14836 :     }
     333                 :      14836 : }
     334                 :            : 
     335                 :            : } // namespace framework
     336                 :            : 
     337                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10