1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <cppuhelper/supportsservice.hxx>
21 #include <X11_selection.hxx>
24 using namespace com::sun::star::uno
;
25 using namespace com::sun::star::lang
;
26 using namespace com::sun::star::awt
;
27 using namespace com::sun::star::datatransfer
;
28 using namespace com::sun::star::datatransfer::dnd
;
30 DropTarget::DropTarget() :
31 ::cppu::WeakComponentImplHelper3
<
37 m_nDefaultActions( 0 ),
38 m_aTargetWindow( None
),
39 m_pSelectionManager( NULL
)
43 DropTarget::~DropTarget()
45 if( m_pSelectionManager
)
46 m_pSelectionManager
->deregisterDropTarget( m_aTargetWindow
);
49 void DropTarget::initialize( const Sequence
< Any
>& arguments
) throw( ::com::sun::star::uno::Exception
, std::exception
)
51 if( arguments
.getLength() > 1 )
53 OUString aDisplayName
;
54 Reference
< XDisplayConnection
> xConn
;
55 arguments
.getConstArray()[0] >>= xConn
;
59 aIdentifier
>>= aDisplayName
;
62 m_pSelectionManager
= &SelectionManager::get( aDisplayName
);
63 m_xSelectionManager
= static_cast< XDragSource
* >(m_pSelectionManager
);
64 m_pSelectionManager
->initialize( arguments
);
66 if( m_pSelectionManager
->getDisplay() ) // #136582# sanity check
68 sal_Size aWindow
= None
;
69 arguments
.getConstArray()[1] >>= aWindow
;
70 m_pSelectionManager
->registerDropTarget( aWindow
, this );
71 m_aTargetWindow
= aWindow
;
77 void DropTarget::addDropTargetListener( const Reference
< XDropTargetListener
>& xListener
) throw(std::exception
)
79 ::osl::Guard
< ::osl::Mutex
> aGuard( m_aMutex
);
81 m_aListeners
.push_back( xListener
);
84 void DropTarget::removeDropTargetListener( const Reference
< XDropTargetListener
>& xListener
) throw(std::exception
)
86 ::osl::Guard
< ::osl::Mutex
> aGuard( m_aMutex
);
88 m_aListeners
.remove( xListener
);
91 sal_Bool
DropTarget::isActive() throw(std::exception
)
96 void DropTarget::setActive( sal_Bool active
) throw(std::exception
)
98 ::osl::Guard
< ::osl::Mutex
> aGuard( m_aMutex
);
103 sal_Int8
DropTarget::getDefaultActions() throw(std::exception
)
105 return m_nDefaultActions
;
108 void DropTarget::setDefaultActions( sal_Int8 actions
) throw(std::exception
)
110 ::osl::Guard
< ::osl::Mutex
> aGuard( m_aMutex
);
112 m_nDefaultActions
= actions
;
115 void DropTarget::drop( const DropTargetDropEvent
& dtde
) throw()
117 osl::ClearableGuard
< ::osl::Mutex
> aGuard( m_aMutex
);
118 std::list
< Reference
< XDropTargetListener
> > aListeners( m_aListeners
);
121 for( std::list
< Reference
< XDropTargetListener
> >::iterator it
= aListeners
.begin(); it
!= aListeners
.end(); ++it
)
127 void DropTarget::dragEnter( const DropTargetDragEnterEvent
& dtde
) throw()
129 osl::ClearableGuard
< ::osl::Mutex
> aGuard( m_aMutex
);
130 std::list
< Reference
< XDropTargetListener
> > aListeners( m_aListeners
);
133 for( std::list
< Reference
< XDropTargetListener
> >::iterator it
= aListeners
.begin(); it
!= aListeners
.end(); ++it
)
135 (*it
)->dragEnter( dtde
);
139 void DropTarget::dragExit( const DropTargetEvent
& dte
) throw()
141 osl::ClearableGuard
< ::osl::Mutex
> aGuard( m_aMutex
);
142 std::list
< Reference
< XDropTargetListener
> > aListeners( m_aListeners
);
145 for( std::list
< Reference
< XDropTargetListener
> >::iterator it
= aListeners
.begin(); it
!= aListeners
.end(); ++it
)
147 (*it
)->dragExit( dte
);
151 void DropTarget::dragOver( const DropTargetDragEvent
& dtde
) throw()
153 osl::ClearableGuard
< ::osl::Mutex
> aGuard( m_aMutex
);
154 std::list
< Reference
< XDropTargetListener
> > aListeners( m_aListeners
);
157 for( std::list
< Reference
< XDropTargetListener
> >::iterator it
= aListeners
.begin(); it
!= aListeners
.end(); ++it
)
159 (*it
)->dragOver( dtde
);
164 OUString
DropTarget::getImplementationName() throw(std::exception
)
166 return OUString(XDND_DROPTARGET_IMPLEMENTATION_NAME
);
169 sal_Bool
DropTarget::supportsService( const OUString
& ServiceName
) throw(std::exception
)
171 return cppu::supportsService(this, ServiceName
);
174 Sequence
< OUString
> DropTarget::getSupportedServiceNames() throw(std::exception
)
176 return Xdnd_dropTarget_getSupportedServiceNames();
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */