LCOV - code coverage report
Current view: top level - framework/source/uielement - addonstoolbarwrapper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 70 81.4 %
Date: 2014-11-03 Functions: 8 9 88.9 %
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        4706 : AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XComponentContext >& xContext ) :
      55             :     UIElementWrapperBase( UIElementType::TOOLBAR ),
      56             :     m_xContext( xContext ),
      57        4706 :     m_bCreatedImages( false )
      58             : {
      59        4706 : }
      60             : 
      61        9408 : AddonsToolBarWrapper::~AddonsToolBarWrapper()
      62             : {
      63        9408 : }
      64             : 
      65             : // XComponent
      66        4704 : void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException, std::exception )
      67             : {
      68        4704 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
      69             : 
      70        9408 :     com::sun::star::lang::EventObject aEvent( xThis );
      71        4704 :     m_aListenerContainer.disposeAndClear( aEvent );
      72             : 
      73        9408 :     SolarMutexGuard g;
      74             : 
      75        4704 :     if ( m_xToolBarManager.is() )
      76        4704 :         m_xToolBarManager->dispose();
      77        4704 :     m_xToolBarManager.clear();
      78             : 
      79        9408 :     m_bDisposed = true;
      80        4704 : }
      81             : 
      82             : // XInitialization
      83        4706 : void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException, std::exception )
      84             : {
      85        4706 :     SolarMutexGuard g;
      86             : 
      87        4706 :     if ( m_bDisposed )
      88           0 :         throw DisposedException();
      89             : 
      90        4706 :     if ( !m_bInitialized )
      91             :     {
      92        4706 :         UIElementWrapperBase::initialize( aArguments );
      93             : 
      94       18824 :         for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
      95             :         {
      96       14118 :             PropertyValue aPropValue;
      97       14118 :             if ( aArguments[n] >>= aPropValue )
      98             :             {
      99       14118 :                 if ( aPropValue.Name == "ConfigurationData" )
     100        4706 :                     aPropValue.Value >>= m_aConfigData;
     101             :             }
     102       14118 :         }
     103             : 
     104        4706 :         Reference< XFrame > xFrame( m_xWeakFrame );
     105        4706 :         if ( xFrame.is() && m_aConfigData.getLength() > 0 )
     106             :         {
     107             :             // Create VCL based toolbar which will be filled with settings data
     108        4706 :             ToolBox* pToolBar = 0;
     109        4706 :             AddonsToolBarManager* pToolBarManager = 0;
     110             :             {
     111        4706 :                 SolarMutexGuard aSolarMutexGuard;
     112        4706 :                 vcl::Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     113        4706 :                 if ( pWindow )
     114             :                 {
     115        4706 :                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
     116             : 
     117        4706 :                     pToolBar = new ToolBox( pWindow, nStyles );
     118        4706 :                     pToolBarManager = new AddonsToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
     119        4706 :                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
     120        4706 :                 }
     121             :             }
     122             : 
     123             :             try
     124             :             {
     125        4706 :                 if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
     126             :                 {
     127             :                     // Fill toolbar with container contents
     128        4706 :                     pToolBarManager->FillToolbar( m_aConfigData );
     129        4706 :                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
     130        4706 :                     pToolBar->EnableCustomize( true );
     131        4706 :                     ::Size aActSize( pToolBar->GetSizePixel() );
     132        4706 :                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
     133        4706 :                     aSize.Width() = aActSize.Width();
     134        4706 :                     pToolBar->SetSizePixel( aSize );
     135             :                 }
     136             :             }
     137           0 :             catch ( const NoSuchElementException& )
     138             :             {
     139             :             }
     140        4706 :         }
     141        4706 :     }
     142        4706 : }
     143             : 
     144             : // XUIElement interface
     145       19160 : Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException, std::exception)
     146             : {
     147       19160 :     SolarMutexGuard g;
     148             : 
     149       19160 :     if ( m_xToolBarManager.is() )
     150             :     {
     151       19160 :         AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
     152       19160 :         if ( pToolBarManager )
     153             :         {
     154       19160 :             vcl::Window* pWindow = (vcl::Window *)pToolBarManager->GetToolBar();
     155       19160 :             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         951 : } // namespace framework
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10