LCOV - code coverage report
Current view: top level - forms/source/richtext - clipboarddispatcher.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 74 0.0 %
Date: 2014-04-14 Functions: 0 13 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 "clipboarddispatcher.hxx"
      21             : #include <editeng/editview.hxx>
      22             : 
      23             : #include <com/sun/star/lang/DisposedException.hpp>
      24             : #include <svtools/cliplistener.hxx>
      25             : #include <svtools/transfer.hxx>
      26             : 
      27             : 
      28             : namespace frm
      29             : {
      30             : 
      31             : 
      32             :     using namespace ::com::sun::star::uno;
      33             :     using namespace ::com::sun::star::frame;
      34             :     using namespace ::com::sun::star::lang;
      35             :     using namespace ::com::sun::star::util;
      36             :     using namespace ::com::sun::star::beans;
      37             : 
      38             : 
      39             :     namespace
      40             :     {
      41           0 :         static URL createClipboardURL( OClipboardDispatcher::ClipboardFunc _eFunc )
      42             :         {
      43           0 :             URL aURL;
      44           0 :             switch ( _eFunc )
      45             :             {
      46             :             case OClipboardDispatcher::eCut:
      47           0 :                 aURL.Complete = ".uno:Cut";
      48           0 :                 break;
      49             :             case OClipboardDispatcher::eCopy:
      50           0 :                 aURL.Complete = ".uno:Copy";
      51           0 :                 break;
      52             :             case OClipboardDispatcher::ePaste:
      53           0 :                 aURL.Complete = ".uno:Paste";
      54           0 :                 break;
      55             :             }
      56           0 :             return aURL;
      57             :         }
      58             :     }
      59             : 
      60             : 
      61             :     //= OClipboardDispatcher
      62             : 
      63             : 
      64           0 :     OClipboardDispatcher::OClipboardDispatcher( EditView& _rView, ClipboardFunc _eFunc )
      65             :         :ORichTextFeatureDispatcher( _rView, createClipboardURL( _eFunc ) )
      66             :         ,m_eFunc( _eFunc )
      67           0 :         ,m_bLastKnownEnabled( sal_True )
      68             :     {
      69           0 :     }
      70             : 
      71             : 
      72           0 :     sal_Bool OClipboardDispatcher::implIsEnabled( ) const
      73             :     {
      74           0 :         sal_Bool bEnabled = sal_False;
      75           0 :         switch ( m_eFunc )
      76             :         {
      77             :         case eCut:
      78           0 :             bEnabled = !getEditView()->IsReadOnly() && getEditView()->HasSelection();
      79           0 :             break;
      80             : 
      81             :         case eCopy:
      82           0 :             bEnabled = getEditView()->HasSelection();
      83           0 :             break;
      84             : 
      85             :         case ePaste:
      86           0 :             bEnabled = !getEditView()->IsReadOnly();
      87           0 :             break;
      88             :         }
      89           0 :         return bEnabled;
      90             :     }
      91             : 
      92             : 
      93           0 :     FeatureStateEvent OClipboardDispatcher::buildStatusEvent() const
      94             :     {
      95           0 :         FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
      96           0 :         aEvent.IsEnabled = implIsEnabled();
      97           0 :         return aEvent;
      98             :     }
      99             : 
     100             : 
     101           0 :     void OClipboardDispatcher::invalidateFeatureState_Broadcast()
     102             :     {
     103           0 :         sal_Bool bEnabled = implIsEnabled();
     104           0 :         if ( m_bLastKnownEnabled == bEnabled )
     105             :             // nothing changed -> no notification
     106           0 :             return;
     107           0 :         m_bLastKnownEnabled = bEnabled;
     108             : 
     109           0 :         ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast();
     110             :     }
     111             : 
     112             : 
     113           0 :     void SAL_CALL OClipboardDispatcher::dispatch( const URL& /*_rURL*/, const Sequence< PropertyValue >& /*Arguments*/ ) throw (RuntimeException, std::exception)
     114             :     {
     115           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     116           0 :         if ( !getEditView() )
     117           0 :             throw DisposedException();
     118             : 
     119           0 :         switch ( m_eFunc )
     120             :         {
     121             :         case eCut:
     122           0 :             getEditView()->Cut();
     123           0 :             break;
     124             : 
     125             :         case eCopy:
     126           0 :             getEditView()->Copy();
     127           0 :             break;
     128             : 
     129             :         case ePaste:
     130           0 :             getEditView()->Paste();
     131           0 :             break;
     132           0 :         }
     133           0 :     }
     134             : 
     135             : 
     136             :     //= OPasteClipboardDispatcher
     137             : 
     138             : 
     139           0 :     OPasteClipboardDispatcher::OPasteClipboardDispatcher( EditView& _rView )
     140             :         :OClipboardDispatcher( _rView, ePaste )
     141             :         ,m_pClipListener( NULL )
     142           0 :         ,m_bPastePossible( sal_False )
     143             :     {
     144           0 :         m_pClipListener = new TransferableClipboardListener( LINK( this, OPasteClipboardDispatcher, OnClipboardChanged ) );
     145           0 :         m_pClipListener->acquire();
     146           0 :         m_pClipListener->AddRemoveListener( _rView.GetWindow(), true );
     147             : 
     148             :         // initial state
     149           0 :         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( _rView.GetWindow() ) );
     150           0 :         m_bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
     151           0 :     }
     152             : 
     153             : 
     154           0 :     OPasteClipboardDispatcher::~OPasteClipboardDispatcher()
     155             :     {
     156           0 :         if ( !isDisposed() )
     157             :         {
     158           0 :             acquire();
     159           0 :             dispose();
     160             :         }
     161           0 :     }
     162             : 
     163             : 
     164           0 :     IMPL_LINK( OPasteClipboardDispatcher, OnClipboardChanged, TransferableDataHelper*, _pDataHelper )
     165             :     {
     166             :         OSL_ENSURE( _pDataHelper, "OPasteClipboardDispatcher::OnClipboardChanged: ooops!" );
     167           0 :         m_bPastePossible = _pDataHelper->HasFormat( SOT_FORMAT_STRING )
     168           0 :                         || _pDataHelper->HasFormat( SOT_FORMAT_RTF );
     169             : 
     170           0 :         invalidate();
     171             : 
     172           0 :         return 0L;
     173             :     }
     174             : 
     175             : 
     176           0 :     void OPasteClipboardDispatcher::disposing( ::osl::ClearableMutexGuard& _rClearBeforeNotify )
     177             :     {
     178             :         OSL_ENSURE( getEditView() && getEditView()->GetWindow(), "OPasteClipboardDispatcher::disposing: EditView should not (yet) be disfunctional here!" );
     179           0 :         if (m_pClipListener)
     180             :         {
     181           0 :             if (getEditView() && getEditView()->GetWindow())
     182           0 :                 m_pClipListener->AddRemoveListener( getEditView()->GetWindow(), false );
     183             : 
     184           0 :             m_pClipListener->release();
     185           0 :             m_pClipListener = NULL;
     186             :         }
     187             : 
     188           0 :         OClipboardDispatcher::disposing( _rClearBeforeNotify );
     189           0 :     }
     190             : 
     191             : 
     192           0 :     sal_Bool OPasteClipboardDispatcher::implIsEnabled( ) const
     193             :     {
     194           0 :         return m_bPastePossible && OClipboardDispatcher::implIsEnabled();
     195             :     }
     196             : 
     197             : 
     198             : }   // namespace frm
     199             : 
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10