Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svtools / source / misc / cliplistener.cxx
blob992d9efb93704dfc1092f6245edc65aee98f094e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
23 #include <vcl/svapp.hxx>
24 #include <vcl/window.hxx>
26 #include <svtools/cliplistener.hxx>
27 #include <vcl/transfer.hxx>
29 using namespace ::com::sun::star;
32 TransferableClipboardListener::TransferableClipboardListener( const Link<TransferableDataHelper*,void>& rCallback ) :
33 aLink( rCallback )
37 TransferableClipboardListener::~TransferableClipboardListener()
41 void SAL_CALL TransferableClipboardListener::disposing( const lang::EventObject& )
45 void SAL_CALL TransferableClipboardListener::changedContents(
46 const datatransfer::clipboard::ClipboardEvent& rEventObject )
48 if ( aLink.IsSet() )
50 const SolarMutexGuard aGuard;
52 TransferableDataHelper aDataHelper( rEventObject.Contents );
53 aLink.Call( &aDataHelper );
57 void TransferableClipboardListener::AddRemoveListener( vcl::Window* pWin, bool bAdd )
59 try
61 if ( pWin )
63 uno::Reference<datatransfer::clipboard::XClipboard> xClipboard = pWin->GetClipboard();
64 uno::Reference<datatransfer::clipboard::XClipboardNotifier> xClpbrdNtfr( xClipboard, uno::UNO_QUERY );
65 if( xClpbrdNtfr.is() )
67 uno::Reference<datatransfer::clipboard::XClipboardListener> xClipEvtLstnr( this );
68 if( bAdd )
69 xClpbrdNtfr->addClipboardListener( xClipEvtLstnr );
70 else
71 xClpbrdNtfr->removeClipboardListener( xClipEvtLstnr );
75 catch( const css::uno::Exception& )
80 void TransferableClipboardListener::ClearCallbackLink()
82 aLink = Link<TransferableDataHelper*,void>();
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */