LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/uno - generictoolboxcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-12-27 Functions: 0 9 0.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 <svtools/generictoolboxcontroller.hxx>
      21             : 
      22             : #include <com/sun/star/util/URLTransformer.hpp>
      23             : #include <com/sun/star/util/XURLTransformer.hpp>
      24             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/lang/DisposedException.hpp>
      27             : #include <com/sun/star/frame/status/ItemStatus.hpp>
      28             : #include <com/sun/star/frame/status/ItemState.hpp>
      29             : 
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <osl/mutex.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : 
      34             : using namespace ::com::sun::star::awt;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::lang;
      38             : using namespace ::com::sun::star::frame;
      39             : using namespace ::com::sun::star::frame::status;
      40             : using namespace ::com::sun::star::util;
      41             : 
      42             : namespace svt
      43             : {
      44             : 
      45           0 : struct ExecuteInfo
      46             : {
      47             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >     xDispatch;
      48             :     ::com::sun::star::util::URL                                                aTargetURL;
      49             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >  aArgs;
      50             : };
      51             : 
      52           0 : GenericToolboxController::GenericToolboxController( const Reference< XMultiServiceFactory >& rServiceManager,
      53             :                                                     const Reference< XFrame >&               rFrame,
      54             :                                                     ToolBox*                                 pToolbox,
      55             :                                                     sal_uInt16                                   nID,
      56             :                                                     const ::rtl::OUString&                          aCommand ) :
      57             :     svt::ToolboxController( rServiceManager, rFrame, aCommand )
      58             :     ,   m_pToolbox( pToolbox )
      59           0 :     ,   m_nID( nID )
      60             : {
      61             :     // Initialization is done through ctor
      62           0 :     m_bInitialized = sal_True;
      63             : 
      64             :     // insert main command to our listener map
      65           0 :     if ( !m_aCommandURL.isEmpty() )
      66           0 :         m_aListenerMap.insert( URLToDispatchMap::value_type( aCommand, Reference< XDispatch >() ));
      67           0 : }
      68             : 
      69           0 : GenericToolboxController::~GenericToolboxController()
      70             : {
      71           0 : }
      72             : 
      73           0 : void SAL_CALL GenericToolboxController::dispose()
      74             : throw ( RuntimeException )
      75             : {
      76           0 :     SolarMutexGuard aSolarMutexGuard;
      77             : 
      78           0 :     svt::ToolboxController::dispose();
      79             : 
      80           0 :     m_pToolbox = 0;
      81           0 :     m_nID = 0;
      82           0 : }
      83             : 
      84           0 : void SAL_CALL GenericToolboxController::execute( sal_Int16 /*KeyModifier*/ )
      85             : throw ( RuntimeException )
      86             : {
      87           0 :     Reference< XDispatch >       xDispatch;
      88           0 :     Reference< XURLTransformer > xURLTransformer;
      89           0 :     ::rtl::OUString                     aCommandURL;
      90             : 
      91             :     {
      92           0 :         SolarMutexGuard aSolarMutexGuard;
      93             : 
      94           0 :         if ( m_bDisposed )
      95           0 :             throw DisposedException();
      96             : 
      97           0 :         if ( m_bInitialized &&
      98           0 :              m_xFrame.is() &&
      99           0 :              m_xServiceManager.is() &&
     100           0 :              !m_aCommandURL.isEmpty() )
     101             :         {
     102           0 :             xURLTransformer = com::sun::star::util::URLTransformer::create( ::comphelper::getComponentContext(m_xServiceManager) );
     103             : 
     104           0 :             aCommandURL = m_aCommandURL;
     105           0 :             URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
     106           0 :             if ( pIter != m_aListenerMap.end() )
     107           0 :                 xDispatch = pIter->second;
     108           0 :         }
     109             :     }
     110             : 
     111           0 :     if ( xDispatch.is() && xURLTransformer.is() )
     112             :     {
     113           0 :         com::sun::star::util::URL aTargetURL;
     114           0 :         Sequence<PropertyValue>   aArgs;
     115             : 
     116           0 :         aTargetURL.Complete = aCommandURL;
     117           0 :         xURLTransformer->parseStrict( aTargetURL );
     118             : 
     119             :         // Execute dispatch asynchronously
     120           0 :         ExecuteInfo* pExecuteInfo = new ExecuteInfo;
     121           0 :         pExecuteInfo->xDispatch     = xDispatch;
     122           0 :         pExecuteInfo->aTargetURL    = aTargetURL;
     123           0 :         pExecuteInfo->aArgs         = aArgs;
     124           0 :         Application::PostUserEvent( STATIC_LINK(0, GenericToolboxController , ExecuteHdl_Impl), pExecuteInfo );
     125           0 :     }
     126           0 : }
     127             : 
     128           0 : void GenericToolboxController::statusChanged( const FeatureStateEvent& Event )
     129             : throw ( RuntimeException )
     130             : {
     131           0 :     SolarMutexGuard aSolarMutexGuard;
     132             : 
     133           0 :     if ( m_bDisposed )
     134           0 :         return;
     135             : 
     136           0 :     if ( m_pToolbox )
     137             :     {
     138           0 :         m_pToolbox->EnableItem( m_nID, Event.IsEnabled );
     139             : 
     140           0 :         sal_uInt16 nItemBits = m_pToolbox->GetItemBits( m_nID );
     141           0 :         nItemBits &= ~TIB_CHECKABLE;
     142           0 :         TriState eTri = STATE_NOCHECK;
     143             : 
     144           0 :         sal_Bool        bValue = sal_Bool();
     145           0 :         rtl::OUString   aStrValue;
     146           0 :         ItemStatus      aItemState;
     147             : 
     148           0 :         if ( Event.State >>= bValue )
     149             :         {
     150             :             // Boolean, treat it as checked/unchecked
     151           0 :             m_pToolbox->SetItemBits( m_nID, nItemBits );
     152           0 :             m_pToolbox->CheckItem( m_nID, bValue );
     153           0 :             if ( bValue )
     154           0 :                 eTri = STATE_CHECK;
     155           0 :             nItemBits |= TIB_CHECKABLE;
     156             :         }
     157           0 :         else if ( Event.State >>= aStrValue )
     158             :         {
     159           0 :             m_pToolbox->SetItemText( m_nID, aStrValue );
     160             :         }
     161           0 :         else if ( Event.State >>= aItemState )
     162             :         {
     163           0 :             eTri = STATE_DONTKNOW;
     164           0 :             nItemBits |= TIB_CHECKABLE;
     165             :         }
     166             : 
     167           0 :         m_pToolbox->SetItemState( m_nID, eTri );
     168           0 :         m_pToolbox->SetItemBits( m_nID, nItemBits );
     169           0 :     }
     170             : }
     171             : 
     172           0 : IMPL_STATIC_LINK_NOINSTANCE( GenericToolboxController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
     173             : {
     174             :    try
     175             :    {
     176             :        // Asynchronous execution as this can lead to our own destruction!
     177             :        // Framework can recycle our current frame and the layout manager disposes all user interface
     178             :        // elements if a component gets detached from its frame!
     179           0 :        pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
     180             :    }
     181           0 :    catch ( Exception& )
     182             :    {
     183             :    }
     184           0 :    delete pExecuteInfo;
     185           0 :    return 0;
     186             : }
     187             : 
     188             : } // namespace
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10