LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - addonstoolbarwrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 59 62 95.2 %
Date: 2012-12-27 Functions: 6 6 100.0 %
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/addonstoolbarwrapper.hxx>
      21             : #include <threadhelp/resetableguard.hxx>
      22             : #include <framework/actiontriggerhelper.hxx>
      23             : #include <uielement/constitemcontainer.hxx>
      24             : #include <uielement/rootitemcontainer.hxx>
      25             : #include <uielement/addonstoolbarmanager.hxx>
      26             : 
      27             : #include <uielement/toolbar.hxx>
      28             : 
      29             : #include <com/sun/star/lang/XServiceInfo.hpp>
      30             : #include <com/sun/star/lang/DisposedException.hpp>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
      33             : #include <com/sun/star/awt/XMenuBar.hpp>
      34             : #include <com/sun/star/container/XIndexContainer.hpp>
      35             : #include <com/sun/star/container/XNameAccess.hpp>
      36             : #include <com/sun/star/ui/UIElementType.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::uno;
      48             : using namespace com::sun::star::beans;
      49             : using namespace com::sun::star::frame;
      50             : using namespace com::sun::star::lang;
      51             : using namespace com::sun::star::container;
      52             : using namespace com::sun::star::awt;
      53             : using namespace ::com::sun::star::ui;
      54             : 
      55             : namespace framework
      56             : {
      57             : 
      58         236 : AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
      59             :     UIElementWrapperBase( UIElementType::TOOLBAR ),
      60         236 :     m_xServiceManager( xServiceManager )
      61             : {
      62         236 : }
      63             : 
      64         126 : AddonsToolBarWrapper::~AddonsToolBarWrapper()
      65             : {
      66         126 : }
      67             : 
      68             : // XComponent
      69          63 : void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
      70             : {
      71          63 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
      72             : 
      73          63 :     com::sun::star::lang::EventObject aEvent( xThis );
      74          63 :     m_aListenerContainer.disposeAndClear( aEvent );
      75             : 
      76          63 :     ResetableGuard aLock( m_aLock );
      77             : 
      78          63 :     if ( m_xToolBarManager.is() )
      79          63 :         m_xToolBarManager->dispose();
      80          63 :     m_xToolBarManager.clear();
      81          63 :     m_xToolBarWindow.clear();
      82             : 
      83          63 :     m_bDisposed = sal_True;
      84          63 : }
      85             : 
      86             : // XInitialization
      87         236 : void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
      88             : {
      89         236 :     ResetableGuard aLock( m_aLock );
      90             : 
      91         236 :     if ( m_bDisposed )
      92           0 :         throw DisposedException();
      93             : 
      94         236 :     if ( !m_bInitialized )
      95             :     {
      96         236 :         UIElementWrapperBase::initialize( aArguments );
      97             : 
      98         944 :         for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
      99             :         {
     100         708 :             PropertyValue aPropValue;
     101         708 :             if ( aArguments[n] >>= aPropValue )
     102             :             {
     103         708 :                 if ( aPropValue.Name == "ConfigurationData" )
     104         236 :                     aPropValue.Value >>= m_aConfigData;
     105             :             }
     106         708 :         }
     107             : 
     108         236 :         Reference< XFrame > xFrame( m_xWeakFrame );
     109         236 :         if ( xFrame.is() && m_aConfigData.getLength() > 0 )
     110             :         {
     111             :             // Create VCL based toolbar which will be filled with settings data
     112         236 :             ToolBar* pToolBar = 0;
     113         236 :             AddonsToolBarManager* pToolBarManager = 0;
     114             :             {
     115         236 :                 SolarMutexGuard aSolarMutexGuard;
     116         236 :                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     117         236 :                 if ( pWindow )
     118             :                 {
     119         236 :                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
     120             : 
     121         236 :                     pToolBar = new ToolBar( pWindow, nStyles );
     122         236 :                     m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
     123         236 :                     pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
     124         236 :                     pToolBar->SetToolBarManager( pToolBarManager );
     125         236 :                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
     126         236 :                 }
     127             :             }
     128             : 
     129             :             try
     130             :             {
     131         236 :                 if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
     132             :                 {
     133             :                     // Fill toolbar with container contents
     134         236 :                     pToolBarManager->FillToolbar( m_aConfigData );
     135         236 :                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
     136         236 :                     pToolBar->EnableCustomize( sal_True );
     137         236 :                     ::Size aActSize( pToolBar->GetSizePixel() );
     138         236 :                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
     139         236 :                     aSize.Width() = aActSize.Width();
     140         236 :                     pToolBar->SetSizePixel( aSize );
     141             :                 }
     142             :             }
     143           0 :             catch ( const NoSuchElementException& )
     144             :             {
     145             :             }
     146         236 :         }
     147         236 :     }
     148         236 : }
     149             : 
     150             : // XUIElement interface
     151        1076 : Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
     152             : {
     153        1076 :     ResetableGuard aLock( m_aLock );
     154             : 
     155        1076 :     if ( m_xToolBarManager.is() )
     156             :     {
     157        1076 :         AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
     158        1076 :         if ( pToolBarManager )
     159             :         {
     160        1076 :             Window* pWindow = (Window *)pToolBarManager->GetToolBar();
     161        1076 :             return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
     162             :         }
     163             :     }
     164             : 
     165           0 :     return Reference< XInterface >();
     166             : }
     167             : 
     168             : } // namespace framework
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10