LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - toolbarwrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 95 144 66.0 %
Date: 2012-12-17 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        1062 : ToolBarWrapper::ToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
      60        1062 :     UIConfigElementWrapperBase( UIElementType::TOOLBAR,xServiceManager )
      61             : {
      62        1062 : }
      63             : 
      64         404 : ToolBarWrapper::~ToolBarWrapper()
      65             : {
      66         404 : }
      67             : 
      68             : // XInterface
      69       35225 : void SAL_CALL ToolBarWrapper::acquire() throw()
      70             : {
      71       35225 :     UIConfigElementWrapperBase::acquire();
      72       35225 : }
      73             : 
      74       34365 : void SAL_CALL ToolBarWrapper::release() throw()
      75             : {
      76       34365 :     UIConfigElementWrapperBase::release();
      77       34365 : }
      78             : 
      79        5761 : 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        5761 :                 (static_cast< ::com::sun::star::ui::XUIFunctionListener* >(this)) );
      85             : 
      86        5761 :     if( a.hasValue() )
      87           0 :         return a;
      88             : 
      89        5761 :     return UIConfigElementWrapperBase::queryInterface( rType );
      90             : }
      91             : 
      92             : // XComponent
      93         202 : void SAL_CALL ToolBarWrapper::dispose() throw ( RuntimeException )
      94             : {
      95         202 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
      96             : 
      97             :     {
      98         202 :         ResetableGuard aLock( m_aLock );
      99         202 :         if ( m_bDisposed )
     100         404 :             return;
     101             :     }
     102             : 
     103         202 :     com::sun::star::lang::EventObject aEvent( xThis );
     104         202 :     m_aListenerContainer.disposeAndClear( aEvent );
     105             : 
     106         202 :     ResetableGuard aLock( m_aLock );
     107             : 
     108         202 :     if ( m_xToolBarManager.is() )
     109         202 :         m_xToolBarManager->dispose();
     110         202 :     m_xToolBarManager.clear();
     111         202 :     m_xConfigSource.clear();
     112         202 :     m_xConfigData.clear();
     113         202 :     m_xToolBarWindow.clear();
     114             : 
     115         202 :     m_bDisposed = sal_True;
     116             : }
     117             : 
     118             : // XInitialization
     119        1062 : void SAL_CALL ToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
     120             : {
     121        1062 :     ResetableGuard aLock( m_aLock );
     122             : 
     123        1062 :     if ( m_bDisposed )
     124           0 :         throw DisposedException();
     125             : 
     126        1062 :     if ( !m_bInitialized )
     127             :     {
     128        1062 :         UIConfigElementWrapperBase::initialize( aArguments );
     129             : 
     130        1062 :         sal_Bool bPopupMode( sal_False );
     131        5310 :         for ( sal_Int32 i = 0; i < aArguments.getLength(); i++ )
     132             :         {
     133        5310 :             PropertyValue aPropValue;
     134        5310 :             if ( aArguments[i] >>= aPropValue )
     135             :             {
     136        5310 :                 if ( aPropValue.Name.equalsAsciiL( "PopupMode", 9 ))
     137             :                 {
     138        1062 :                     aPropValue.Value >>= bPopupMode;
     139             :                     break;
     140             :                 }
     141             :             }
     142        5310 :         }
     143             : 
     144        1062 :         Reference< XFrame > xFrame( m_xWeakFrame );
     145        1062 :         if ( xFrame.is() && m_xConfigSource.is() )
     146             :         {
     147             :             // Create VCL based toolbar which will be filled with settings data
     148        1062 :             ToolBar* pToolBar = 0;
     149        1062 :             ToolBarManager* pToolBarManager = 0;
     150             :             {
     151        1062 :                 SolarMutexGuard aSolarMutexGuard;
     152        1062 :                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     153        1062 :                 if ( pWindow )
     154             :                 {
     155        1062 :                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
     156             : 
     157        1062 :                     pToolBar = new ToolBar( pWindow, nStyles );
     158        1062 :                     m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
     159        1062 :                     pToolBarManager = new ToolBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pToolBar );
     160        1062 :                     pToolBar->SetToolBarManager( pToolBarManager );
     161        1062 :                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
     162        1062 :                     pToolBar->WillUsePopupMode( bPopupMode );
     163        1062 :                 }
     164             :             }
     165             : 
     166             :             try
     167             :             {
     168        1062 :                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
     169           4 :                 if ( m_xConfigData.is() && pToolBar && pToolBarManager )
     170             :                 {
     171             :                     // Fill toolbar with container contents
     172           4 :                     pToolBarManager->FillToolbar( m_xConfigData );
     173           4 :                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
     174           4 :                     pToolBar->EnableCustomize( sal_True );
     175           4 :                     ::Size aActSize( pToolBar->GetSizePixel() );
     176           4 :                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
     177           4 :                     aSize.Width() = aActSize.Width();
     178           4 :                     pToolBar->SetOutputSizePixel( aSize );
     179             :                 }
     180             :             }
     181        1058 :             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        1058 :                 m_bPersistent = sal_False;
     186        1058 :                 if ( pToolBar && pToolBarManager )
     187             :                 {
     188        1058 :                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
     189        1058 :                     pToolBar->EnableCustomize( sal_True );
     190        1058 :                     ::Size aActSize( pToolBar->GetSizePixel() );
     191        1058 :                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
     192        1058 :                     aSize.Width() = aActSize.Width();
     193        1058 :                     pToolBar->SetOutputSizePixel( aSize );
     194             :                 }
     195             :             }
     196        1062 :         }
     197        1062 :     }
     198        1062 : }
     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        8923 : Reference< XInterface > SAL_CALL ToolBarWrapper::getRealInterface(  ) throw (::com::sun::star::uno::RuntimeException)
     260             : {
     261        8923 :     ResetableGuard aLock( m_aLock );
     262             : 
     263        8923 :     if ( m_xToolBarManager.is() )
     264             :     {
     265        8923 :         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
     266        8923 :         if ( pToolBarManager )
     267             :         {
     268        8923 :             Window* pWindow = (Window *)pToolBarManager->GetToolBar();
     269        8923 :             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        4248 : void SAL_CALL ToolBarWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any&  aValue ) throw( com::sun::star::uno::Exception )
     293             : {
     294        4248 :     ResetableGuard aLock( m_aLock );
     295        4248 :     sal_Bool bNoClose( m_bNoClose );
     296        4248 :     aLock.unlock();
     297             : 
     298        4248 :     UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
     299             : 
     300        4248 :     aLock.lock();
     301             : 
     302        4248 :     sal_Bool bNewNoClose( m_bNoClose );
     303        4248 :     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        4248 :     }
     324        4248 : }
     325             : 
     326             : } // namespace framework
     327             : 
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10