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

Generated by: LCOV version 1.10