/Users/ericb/Desktop/SRC680_m247/starmath/source/viewhdl.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: viewhdl.cxx,v $
00006  *
00007  *  $Revision: 1.9 $
00008  *
00009  *  last change: $Author: vg $ $Date: 2007/05/25 12:16:55 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 
00036 // MARKER(update_precomp.py): autogen include statement, do not remove
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 // --------------------------- Clipboard EventListener ------------------
00075 
00076 class SmClipboardChangeListener : public ::cppu::WeakImplHelper1<
00077         ::com::sun::star::datatransfer::clipboard::XClipboardListener >
00078 {
00079         SmViewShell*    pView;
00080 
00081         // XEventListener
00082         virtual void SAL_CALL disposing(
00083                         const lang::EventObject& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
00084 ;//                                                     throw( UNO_NMSPC::RuntimeException );
00085 
00086         // XClipboardListener
00087         virtual void SAL_CALL changedContents(
00088                         const datatransfer::clipboard::ClipboardEvent& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
00089 ;//                                                                             throw( UNO_NMSPC::RuntimeException );
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 // ------------------------- SmClipboardChangeListener ---------------------
00103 
00104 SmClipboardChangeListener::~SmClipboardChangeListener()
00105 {
00106 }
00107 
00108 void SAL_CALL SmClipboardChangeListener::disposing(
00109                                     const lang::EventObject& /*rEventObject*/ ) 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 // ------------------------- SmViewShell ---------------------
00174 
00175 void SmViewShell::AddRemoveClipboardListener( BOOL bAdd )
00176 {
00177     // AddRemoveListener and ViewDestroyed below should be an 
00178     // atomic operation and must not be 'interrupted' by other code
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 

Generated on Wed Feb 20 17:21:57 2008 for maths by  doxygen 1.5.1