Files
libreoffice/vcl/source/components/dtranscomp.cxx
Stephan Bergmann f853ec317f Extend loplugin:external to warn about classes
...following up on 314f15bff0 "Extend
loplugin:external to warn about enums".

Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:

  filter/source/svg/svgexport.cxx
  sc/source/filter/excel/xelink.cxx
  sc/source/filter/excel/xilink.cxx
  svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx

All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage.  (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)

For friend declarations using elaborate type specifiers, like

  class C1 {};
  class C2 { friend class C1; };

* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")

* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".

Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace.  But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".

Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.

And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.

And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is.  GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>)  The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.

Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-22 12:57:32 +01:00

473 lines
14 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <factory.hxx>
#include <svdata.hxx>
#include <salinst.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
#include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/supportsservice.hxx>
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
namespace vcl
{
namespace {
// generic implementation to satisfy SalInstance
class GenericClipboard :
public cppu::WeakComponentImplHelper<
datatransfer::clipboard::XSystemClipboard,
XServiceInfo
>
{
osl::Mutex m_aMutex;
Reference< css::datatransfer::XTransferable > m_aContents;
Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner;
std::vector< Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners;
public:
GenericClipboard() : cppu::WeakComponentImplHelper<
datatransfer::clipboard::XSystemClipboard,
XServiceInfo
>( m_aMutex )
{}
/*
* XServiceInfo
*/
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
static Sequence< OUString > getSupportedServiceNames_static();
/*
* XClipboard
*/
virtual Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override;
virtual void SAL_CALL setContents(
const Reference< css::datatransfer::XTransferable >& xTrans,
const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) override;
virtual OUString SAL_CALL getName() override;
/*
* XClipboardEx
*/
virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
/*
* XClipboardNotifier
*/
virtual void SAL_CALL addClipboardListener(
const Reference< css::datatransfer::clipboard::XClipboardListener >& listener ) override;
virtual void SAL_CALL removeClipboardListener(
const Reference< css::datatransfer::clipboard::XClipboardListener >& listener ) override;
};
}
Sequence< OUString > GenericClipboard::getSupportedServiceNames_static()
{
Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.SystemClipboard" };
return aRet;
}
OUString GenericClipboard::getImplementationName()
{
return "com.sun.star.datatransfer.VCLGenericClipboard";
}
Sequence< OUString > GenericClipboard::getSupportedServiceNames()
{
return getSupportedServiceNames_static();
}
sal_Bool GenericClipboard::supportsService( const OUString& ServiceName )
{
return cppu::supportsService(this, ServiceName);
}
Reference< css::datatransfer::XTransferable > GenericClipboard::getContents()
{
return m_aContents;
}
void GenericClipboard::setContents(
const Reference< css::datatransfer::XTransferable >& xTrans,
const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
{
osl::ClearableMutexGuard aGuard( m_aMutex );
Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner );
Reference< datatransfer::XTransferable > xOldContents( m_aContents );
m_aContents = xTrans;
m_aOwner = xClipboardOwner;
std::vector< Reference< datatransfer::clipboard::XClipboardListener > > aListeners( m_aListeners );
datatransfer::clipboard::ClipboardEvent aEv;
aEv.Contents = m_aContents;
aGuard.clear();
if( xOldOwner.is() && xOldOwner != xClipboardOwner )
xOldOwner->lostOwnership( this, xOldContents );
for (auto const& listener : aListeners)
{
listener->changedContents( aEv );
}
}
OUString GenericClipboard::getName()
{
return "CLIPBOARD";
}
sal_Int8 GenericClipboard::getRenderingCapabilities()
{
return 0;
}
void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
{
osl::MutexGuard aGuard(m_aMutex);
m_aListeners.push_back( listener );
}
void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
{
osl::MutexGuard aGuard(m_aMutex);
m_aListeners.erase(std::remove(m_aListeners.begin(), m_aListeners.end(), listener), m_aListeners.end());
}
namespace {
class ClipboardFactory : public ::cppu::WeakComponentImplHelper<
css::lang::XSingleServiceFactory
>
{
osl::Mutex m_aMutex;
public:
ClipboardFactory();
/*
* XSingleServiceFactory
*/
virtual Reference< XInterface > SAL_CALL createInstance() override;
virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) override;
};
}
ClipboardFactory::ClipboardFactory() :
cppu::WeakComponentImplHelper<
css::lang::XSingleServiceFactory
>( m_aMutex )
{
}
Reference< XInterface > ClipboardFactory::createInstance()
{
return createInstanceWithArguments( Sequence< Any >() );
}
Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments )
{
SolarMutexGuard aGuard;
Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments );
return xResult;
}
OUString Clipboard_getImplementationName()
{
return
#if defined MACOSX
"com.sun.star.datatransfer.clipboard.AquaClipboard"
#elif defined IOS
"com.sun.star.datatransfer.clipboard.iOSClipboard"
#elif defined ANDROID
"com.sun.star.datatransfer.VCLGenericClipboard"
#elif defined UNX
"com.sun.star.datatransfer.X11ClipboardSupport"
#else
"com.sun.star.datatransfer.VCLGenericClipboard"
#endif
;
}
Reference< XSingleServiceFactory > Clipboard_createFactory()
{
return Reference< XSingleServiceFactory >( new ClipboardFactory() );
}
namespace {
/*
* generic DragSource dummy
*/
class GenericDragSource : public cppu::WeakComponentImplHelper<
datatransfer::dnd::XDragSource,
XInitialization,
css::lang::XServiceInfo
>
{
osl::Mutex m_aMutex;
public:
GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {}
// XDragSource
virtual sal_Bool SAL_CALL isDragImageSupported() override;
virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) override;
virtual void SAL_CALL startDrag(
const datatransfer::dnd::DragGestureEvent& trigger,
sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
const Reference< datatransfer::XTransferable >& transferable,
const Reference< datatransfer::dnd::XDragSourceListener >& listener
) override;
// XInitialization
virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) override;
OUString SAL_CALL getImplementationName() override
{ return "com.sun.star.datatransfer.dnd.VclGenericDragSource"; }
sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
{ return cppu::supportsService(this, ServiceName); }
css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
{ return getSupportedServiceNames_static(); }
static Sequence< OUString > getSupportedServiceNames_static()
{
Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDragSource" };
return aRet;
}
};
}
sal_Bool GenericDragSource::isDragImageSupported()
{
return false;
}
sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 )
{
return 0;
}
void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
const Reference< datatransfer::XTransferable >&,
const Reference< datatransfer::dnd::XDragSourceListener >& listener
)
{
datatransfer::dnd::DragSourceDropEvent aEv;
aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
aEv.DropSuccess = false;
listener->dragDropEnd( aEv );
}
void GenericDragSource::initialize( const Sequence< Any >& )
{
}
Sequence< OUString > DragSource_getSupportedServiceNames()
{
#if defined MACOSX
return { "com.sun.star.datatransfer.dnd.OleDragSource" };
#elif defined UNX
return { "com.sun.star.datatransfer.dnd.X11DragSource" };
#else
return { "com.sun.star.datatransfer.dnd.VclGenericDragSource" };
#endif
}
OUString DragSource_getImplementationName()
{
#if defined MACOSX
return "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1";
#elif defined UNX
return "com.sun.star.datatransfer.dnd.XdndSupport";
#else
return "com.sun.star.datatransfer.dnd.VclGenericDragSource";
#endif
}
Reference< XInterface > DragSource_createInstance( const Reference< XMultiServiceFactory >& )
{
SolarMutexGuard aGuard;
Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource();
return xResult;
}
/*
* generic DragSource dummy
*/
namespace {
class GenericDropTarget : public cppu::WeakComponentImplHelper<
datatransfer::dnd::XDropTarget,
XInitialization,
css::lang::XServiceInfo
>
{
osl::Mutex m_aMutex;
public:
GenericDropTarget() : WeakComponentImplHelper( m_aMutex )
{}
// XInitialization
virtual void SAL_CALL initialize( const Sequence< Any >& args ) override;
// XDropTarget
virtual void SAL_CALL addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) override;
virtual void SAL_CALL removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) override;
virtual sal_Bool SAL_CALL isActive() override;
virtual void SAL_CALL setActive( sal_Bool active ) override;
virtual sal_Int8 SAL_CALL getDefaultActions() override;
virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) override;
OUString SAL_CALL getImplementationName() override
{ return "com.sun.star.datatransfer.dnd.VclGenericDropTarget"; }
sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
{ return cppu::supportsService(this, ServiceName); }
css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
{ return getSupportedServiceNames_static(); }
static Sequence< OUString > getSupportedServiceNames_static()
{
Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDropTarget" };
return aRet;
}
};
}
void GenericDropTarget::initialize( const Sequence< Any >& )
{
}
void GenericDropTarget::addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& )
{
}
void GenericDropTarget::removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& )
{
}
sal_Bool GenericDropTarget::isActive()
{
return false;
}
void GenericDropTarget::setActive( sal_Bool )
{
}
sal_Int8 GenericDropTarget::getDefaultActions()
{
return 0;
}
void GenericDropTarget::setDefaultActions( sal_Int8)
{
}
Sequence< OUString > DropTarget_getSupportedServiceNames()
{
#if defined MACOSX
return { "com.sun.star.datatransfer.dnd.OleDropTarget" };
#elif defined UNX
return { "com.sun.star.datatransfer.dnd.X11DropTarget" };
#else
return GenericDropTarget::getSupportedServiceNames_static();
#endif
}
OUString DropTarget_getImplementationName()
{
return
#if defined MACOSX
"com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
#elif defined UNX
"com.sun.star.datatransfer.dnd.XdndDropTarget"
#else
"com.sun.star.datatransfer.dnd.VclGenericDropTarget"
#endif
;
}
Reference< XInterface > DropTarget_createInstance( const Reference< XMultiServiceFactory >& )
{
SolarMutexGuard aGuard;
Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget();
return xResult;
}
} // namespace vcl
/*
* SalInstance generic
*/
Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& )
{
return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericClipboard()) );
}
Reference< XInterface > SalInstance::CreateDragSource()
{
return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDragSource()) );
}
Reference< XInterface > SalInstance::CreateDropTarget()
{
return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDropTarget()) );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */