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

Generated by: LCOV version 1.10