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

Generated by: LCOV version 1.10