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 :
21 : #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
22 :
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/window.hxx>
25 : #include <osl/mutex.hxx>
26 :
27 : #include <svtools/cliplistener.hxx>
28 : #include <svtools/transfer.hxx>
29 :
30 : using namespace ::com::sun::star;
31 :
32 :
33 :
34 225 : TransferableClipboardListener::TransferableClipboardListener( const Link<>& rCallback ) :
35 225 : aLink( rCallback )
36 : {
37 225 : }
38 :
39 446 : TransferableClipboardListener::~TransferableClipboardListener()
40 : {
41 446 : }
42 :
43 0 : void SAL_CALL TransferableClipboardListener::disposing( const lang::EventObject& )
44 : throw(uno::RuntimeException, std::exception)
45 : {
46 0 : }
47 :
48 0 : void SAL_CALL TransferableClipboardListener::changedContents(
49 : const datatransfer::clipboard::ClipboardEvent& rEventObject )
50 : throw(uno::RuntimeException, std::exception)
51 : {
52 0 : if ( aLink.IsSet() )
53 : {
54 0 : const SolarMutexGuard aGuard;
55 :
56 0 : TransferableDataHelper aDataHelper( rEventObject.Contents );
57 0 : aLink.Call( &aDataHelper );
58 : }
59 0 : }
60 :
61 448 : void TransferableClipboardListener::AddRemoveListener( vcl::Window* pWin, bool bAdd )
62 : {
63 : try
64 : {
65 448 : if ( pWin )
66 : {
67 448 : uno::Reference<datatransfer::clipboard::XClipboard> xClipboard = pWin->GetClipboard();
68 896 : uno::Reference<datatransfer::clipboard::XClipboardNotifier> xClpbrdNtfr( xClipboard, uno::UNO_QUERY );
69 448 : if( xClpbrdNtfr.is() )
70 : {
71 438 : uno::Reference<datatransfer::clipboard::XClipboardListener> xClipEvtLstnr( this );
72 438 : if( bAdd )
73 219 : xClpbrdNtfr->addClipboardListener( xClipEvtLstnr );
74 : else
75 219 : xClpbrdNtfr->removeClipboardListener( xClipEvtLstnr );
76 448 : }
77 : }
78 : }
79 0 : catch( const ::com::sun::star::uno::Exception& )
80 : {
81 : }
82 448 : }
83 :
84 223 : void TransferableClipboardListener::ClearCallbackLink()
85 : {
86 223 : aLink = Link<>();
87 223 : }
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|