00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "precompiled_starmath.hxx"
00038
00039
00040 #include <view.hxx>
00041
00042 #ifndef _COMPHELPER_PROCESSFACTORY_HXX_
00043 #include <comphelper/processfactory.hxx>
00044 #endif
00045 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
00046 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
00047 #endif
00048 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARDLISTENER_HPP_
00049 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
00050 #endif
00051 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARDNOTIFIER_HPP_
00052 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
00053 #endif
00054 #ifndef _VOS_MUTEX_HXX_
00055 #include <vos/mutex.hxx>
00056 #endif
00057 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
00058 #include <cppuhelper/implbase1.hxx>
00059 #endif
00060 #ifndef _TRANSFER_HXX
00061 #include <svtools/transfer.hxx>
00062 #endif
00063 #ifndef _SFX_BINDINGS_HXX
00064 #include <sfx2/bindings.hxx>
00065 #endif
00066 #ifndef _SFXSIDS_HRC
00067 #include <sfx2/sfxsids.hrc>
00068 #endif
00069
00070 using namespace ::com::sun::star;
00071 using namespace ::com::sun::star::uno;
00072 using namespace ::com::sun::star::datatransfer::clipboard;
00073
00074
00075
00076 class SmClipboardChangeListener : public ::cppu::WeakImplHelper1<
00077 ::com::sun::star::datatransfer::clipboard::XClipboardListener >
00078 {
00079 SmViewShell* pView;
00080
00081
00082 virtual void SAL_CALL disposing(
00083 const lang::EventObject& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
00084 ;
00085
00086
00087 virtual void SAL_CALL changedContents(
00088 const datatransfer::clipboard::ClipboardEvent& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
00089 ;
00090
00091 public:
00092 SmClipboardChangeListener( SmViewShell& rView ) : pView( &rView ) {}
00093 virtual ~SmClipboardChangeListener();
00094
00095 void ViewDestroyed() { pView = 0; }
00096
00097 void AddRemoveListener( BOOL bAdd );
00098 };
00099
00100
00101
00102
00103
00104 SmClipboardChangeListener::~SmClipboardChangeListener()
00105 {
00106 }
00107
00108 void SAL_CALL SmClipboardChangeListener::disposing(
00109 const lang::EventObject& ) throw ( ::com::sun::star::uno::RuntimeException)
00110 {
00111 }
00112
00113 void SAL_CALL SmClipboardChangeListener::changedContents(
00114 const ClipboardEvent& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
00115 {
00116 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
00117
00118 if( pView )
00119 {
00120 {
00121 TransferableDataHelper aDataHelper( rEventObject.Contents );
00122 sal_Bool bHasTransferable = aDataHelper.GetTransferable().is();
00123
00127 if (pView)
00128 {
00129 pView->bPasteState = bHasTransferable &&
00130 ( aDataHelper.HasFormat( FORMAT_STRING ) ||
00131 aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
00132 (aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
00133 && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE )));
00134 }
00135 }
00136
00137 if (pView)
00138 {
00139 SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
00140 rBind.Invalidate( SID_PASTE );
00141 }
00142 }
00143 }
00144
00145 void SmClipboardChangeListener::AddRemoveListener( BOOL bAdd )
00146 {
00147 try
00148 {
00149 do {
00150 Window* pW;
00151 Reference< XClipboard > xClipboard;
00152 if( pView && 0 != ( pW = pView->GetEditWindow()) )
00153 xClipboard = pW->GetClipboard();
00154 if( !xClipboard.is() )
00155 break;
00156
00157 Reference< XClipboardNotifier > xClpbrdNtfr( xClipboard, UNO_QUERY );
00158 if( xClpbrdNtfr.is() )
00159 {
00160 Reference< XClipboardListener > xClipEvtLstnr( this );
00161 if( bAdd )
00162 xClpbrdNtfr->addClipboardListener( xClipEvtLstnr );
00163 else
00164 xClpbrdNtfr->removeClipboardListener( xClipEvtLstnr );
00165 }
00166 } while ( FALSE );
00167 }
00168 catch( const ::com::sun::star::uno::Exception& )
00169 {
00170 }
00171 }
00172
00173
00174
00175 void SmViewShell::AddRemoveClipboardListener( BOOL bAdd )
00176 {
00177
00178
00179 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
00180
00181 if( bAdd && !xClipEvtLstnr.is() )
00182 {
00183 xClipEvtLstnr = pClipEvtLstnr = new SmClipboardChangeListener( *this );
00184 pClipEvtLstnr->AddRemoveListener( TRUE );
00185 }
00186 else if( !bAdd && xClipEvtLstnr.is() )
00187 {
00188 pClipEvtLstnr->AddRemoveListener( FALSE );
00189 pClipEvtLstnr->ViewDestroyed();
00190 }
00191 }
00192
00193
00194