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