sync master with lastest vba changes
[ooovba.git] / starmath / source / viewhdl.cxx
blobbfd13945559164ef3a6702f32dade1f1778bcf67
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewhdl.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
35 #include <view.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
39 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
40 #include <vos/mutex.hxx>
41 #include <cppuhelper/implbase1.hxx>
42 #include <svtools/transfer.hxx>
43 #include <sfx2/bindings.hxx>
44 #include <sfx2/sfxsids.hrc>
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::datatransfer::clipboard;
50 // --------------------------- Clipboard EventListener ------------------
52 class SmClipboardChangeListener : public ::cppu::WeakImplHelper1<
53 ::com::sun::star::datatransfer::clipboard::XClipboardListener >
55 SmViewShell* pView;
57 // XEventListener
58 virtual void SAL_CALL disposing(
59 const lang::EventObject& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
60 ;// throw( UNO_NMSPC::RuntimeException );
62 // XClipboardListener
63 virtual void SAL_CALL changedContents(
64 const datatransfer::clipboard::ClipboardEvent& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
65 ;// throw( UNO_NMSPC::RuntimeException );
67 public:
68 SmClipboardChangeListener( SmViewShell& rView ) : pView( &rView ) {}
69 virtual ~SmClipboardChangeListener();
71 void ViewDestroyed() { pView = 0; }
73 void AddRemoveListener( BOOL bAdd );
78 // ------------------------- SmClipboardChangeListener ---------------------
80 SmClipboardChangeListener::~SmClipboardChangeListener()
84 void SAL_CALL SmClipboardChangeListener::disposing(
85 const lang::EventObject& /*rEventObject*/ ) throw ( ::com::sun::star::uno::RuntimeException)
89 void SAL_CALL SmClipboardChangeListener::changedContents(
90 const ClipboardEvent& rEventObject ) throw ( ::com::sun::star::uno::RuntimeException)
92 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
94 if( pView )
97 TransferableDataHelper aDataHelper( rEventObject.Contents );
98 sal_Bool bHasTransferable = aDataHelper.GetTransferable().is();
100 //! according to CD the above call to GetTransferable may create a (new)
101 //! message loop and thus result in re-entrant code.
102 //! Thus it was suggested to check 'pView' here again.
103 if (pView)
105 pView->bPasteState = bHasTransferable &&
106 ( aDataHelper.HasFormat( FORMAT_STRING ) ||
107 aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ||
108 (aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
109 && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE )));
113 if (pView)
115 SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
116 rBind.Invalidate( SID_PASTE );
121 void SmClipboardChangeListener::AddRemoveListener( BOOL bAdd )
125 do {
126 Window* pW;
127 Reference< XClipboard > xClipboard;
128 if( pView && 0 != ( pW = pView->GetEditWindow()) )
129 xClipboard = pW->GetClipboard();
130 if( !xClipboard.is() )
131 break;
133 Reference< XClipboardNotifier > xClpbrdNtfr( xClipboard, UNO_QUERY );
134 if( xClpbrdNtfr.is() )
136 Reference< XClipboardListener > xClipEvtLstnr( this );
137 if( bAdd )
138 xClpbrdNtfr->addClipboardListener( xClipEvtLstnr );
139 else
140 xClpbrdNtfr->removeClipboardListener( xClipEvtLstnr );
142 } while ( FALSE );
144 catch( const ::com::sun::star::uno::Exception& )
149 // ------------------------- SmViewShell ---------------------
151 void SmViewShell::AddRemoveClipboardListener( BOOL bAdd )
153 // AddRemoveListener and ViewDestroyed below should be an
154 // atomic operation and must not be 'interrupted' by other code
155 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
157 if( bAdd && !xClipEvtLstnr.is() )
159 xClipEvtLstnr = pClipEvtLstnr = new SmClipboardChangeListener( *this );
160 pClipEvtLstnr->AddRemoveListener( TRUE );
162 else if( !bAdd && xClipEvtLstnr.is() )
164 pClipEvtLstnr->AddRemoveListener( FALSE );
165 pClipEvtLstnr->ViewDestroyed();