xref: /AOO41X/main/svtools/source/misc/cliplistener.cxx (revision 5900e8ec128faec89519683efce668ccd8cc6084)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
28 
29 #include <vcl/svapp.hxx>
30 #include <vcl/window.hxx>
31 #include <vos/mutex.hxx>
32 
33 #include <svtools/cliplistener.hxx>
34 #include <svtools/transfer.hxx>
35 
36 using namespace ::com::sun::star;
37 
38 // -----------------------------------------------------------------------------
39 
TransferableClipboardListener(const Link & rCallback)40 TransferableClipboardListener::TransferableClipboardListener( const Link& rCallback ) :
41     aLink( rCallback )
42 {
43 }
44 
~TransferableClipboardListener()45 TransferableClipboardListener::~TransferableClipboardListener()
46 {
47 }
48 
disposing(const lang::EventObject &)49 void SAL_CALL TransferableClipboardListener::disposing( const lang::EventObject& )
50                                                         throw(uno::RuntimeException)
51 {
52 }
53 
changedContents(const datatransfer::clipboard::ClipboardEvent & rEventObject)54 void SAL_CALL TransferableClipboardListener::changedContents(
55                             const datatransfer::clipboard::ClipboardEvent& rEventObject )
56                                                         throw(uno::RuntimeException)
57 {
58     if ( aLink.IsSet() )
59     {
60         const ::vos::OGuard aGuard( Application::GetSolarMutex() );
61 
62         TransferableDataHelper aDataHelper( rEventObject.Contents );
63         aLink.Call( &aDataHelper );
64     }
65 }
66 
AddRemoveListener(Window * pWin,sal_Bool bAdd)67 void TransferableClipboardListener::AddRemoveListener( Window* pWin, sal_Bool bAdd )
68 {
69     try
70     {
71         if ( pWin )
72         {
73             uno::Reference<datatransfer::clipboard::XClipboard> xClipboard = pWin->GetClipboard();
74             uno::Reference<datatransfer::clipboard::XClipboardNotifier> xClpbrdNtfr( xClipboard, uno::UNO_QUERY );
75             if( xClpbrdNtfr.is() )
76             {
77                 uno::Reference<datatransfer::clipboard::XClipboardListener> xClipEvtLstnr( this );
78                 if( bAdd )
79                     xClpbrdNtfr->addClipboardListener( xClipEvtLstnr );
80                 else
81                     xClpbrdNtfr->removeClipboardListener( xClipEvtLstnr );
82             }
83         }
84     }
85     catch( const ::com::sun::star::uno::Exception& )
86     {
87     }
88 }
89 
ClearCallbackLink()90 void TransferableClipboardListener::ClearCallbackLink()
91 {
92     aLink = Link();
93 }
94 
95