From f8f43e55ec4ae7e436a5043fe6f4bae7b39cc6ad Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Tue, 9 Jul 2019 20:29:05 +0000 Subject: tdf#126316 revert Clipboard to PrimarySelection Regression from commit ce9795954d39 ("fix crash in header/footer calc dialog"), which replaced some GetPrimarySelection() calls with GetClipboard() calls. This replaces the Window class calls for clipboard with global GetSystem* calls in vcl/transfer.hxx. Not sure if this is the best place, but the crowded Window class is definitly not. Change-Id: Ic5f9e575c1ac5d43df234426c5616eca616dea30 Reviewed-on: https://gerrit.libreoffice.org/75318 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski --- vcl/source/treelist/transfer2.cxx | 41 +++++++++++++++++++++++ vcl/source/window/window.cxx | 69 +++++++-------------------------------- 2 files changed, 52 insertions(+), 58 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/treelist/transfer2.cxx b/vcl/source/treelist/transfer2.cxx index a731ec2abf23..9160ba416e02 100644 --- a/vcl/source/treelist/transfer2.cxx +++ b/vcl/source/treelist/transfer2.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include + #include #include #include @@ -26,9 +28,12 @@ #include #include #include +#include +#include #include #include #include +#include #include #include #include @@ -460,4 +465,40 @@ void TransferDataContainer::DragFinished( sal_Int8 nDropAction ) pImpl->aFinshedLnk.Call( nDropAction ); } +Reference GetSystemClipboard() +{ + Reference xClipboard; + try + { + xClipboard = css::datatransfer::clipboard::SystemClipboard::create( + comphelper::getProcessComponentContext()); + } + catch (DeploymentException const &) {} + return xClipboard; +} + +Reference GetSystemPrimarySelection() +{ + Reference xSelection; + try + { + Reference xContext(comphelper::getProcessComponentContext()); +#if HAVE_FEATURE_X11 + // A hack, making the primary selection available as an instance + // of the SystemClipboard service on X11: + Sequence< Any > args(1); + args[0] <<= OUString("PRIMARY"); + xSelection.set(xContext->getServiceManager()->createInstanceWithArgumentsAndContext( + "com.sun.star.datatransfer.clipboard.SystemClipboard", args, xContext), UNO_QUERY_THROW); +#else + static Reference< XClipboard > s_xSelection( + xContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.datatransfer.clipboard.GenericClipboard", xContext), UNO_QUERY); + xSelection = s_xSelection; +#endif + } + catch (RuntimeException const &) {} + return xSelection; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 826ba0cbadbe..3b26f70d7040 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -3273,68 +3274,20 @@ void Window::SetClipboard(Reference const & xClipboard) Reference< XClipboard > Window::GetClipboard() { - - if( mpWindowImpl->mpFrameData ) - { - if( ! mpWindowImpl->mpFrameData->mxClipboard.is() ) - { - try - { - mpWindowImpl->mpFrameData->mxClipboard - = css::datatransfer::clipboard::SystemClipboard::create( - comphelper::getProcessComponentContext()); - } - catch (DeploymentException const &) - { - TOOLS_WARN_EXCEPTION("vcl.window", "ignoring"); - } - } - - return mpWindowImpl->mpFrameData->mxClipboard; - } - - return static_cast < XClipboard * > (nullptr); + if (!mpWindowImpl->mpFrameData) + return static_cast(nullptr); + if (!mpWindowImpl->mpFrameData->mxClipboard.is()) + mpWindowImpl->mpFrameData->mxClipboard = GetSystemClipboard(); + return mpWindowImpl->mpFrameData->mxClipboard; } Reference< XClipboard > Window::GetPrimarySelection() { - - if( mpWindowImpl->mpFrameData ) - { - if( ! mpWindowImpl->mpFrameData->mxSelection.is() ) - { - try - { - Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); - -#if HAVE_FEATURE_X11 - // A hack, making the primary selection available as an instance - // of the SystemClipboard service on X11: - Sequence< Any > args(1); - args[0] <<= OUString("PRIMARY"); - mpWindowImpl->mpFrameData->mxSelection.set( - (xContext->getServiceManager()-> - createInstanceWithArgumentsAndContext( - "com.sun.star.datatransfer.clipboard.SystemClipboard", - args, xContext)), - UNO_QUERY_THROW); -#else - static Reference< XClipboard > s_xSelection( - xContext->getServiceManager()->createInstanceWithContext( "com.sun.star.datatransfer.clipboard.GenericClipboard", xContext ), UNO_QUERY ); - - mpWindowImpl->mpFrameData->mxSelection = s_xSelection; -#endif - } - catch (RuntimeException const &) - { - TOOLS_WARN_EXCEPTION("vcl.window", "ignoring"); - } - } - - return mpWindowImpl->mpFrameData->mxSelection; - } - - return static_cast < XClipboard * > (nullptr); + if (!mpWindowImpl->mpFrameData) + return static_cast(nullptr); + if (!mpWindowImpl->mpFrameData->mxSelection.is()) + mpWindowImpl->mpFrameData->mxSelection = GetSystemPrimarySelection(); + return mpWindowImpl->mpFrameData->mxSelection; } void Window::RecordLayoutData( vcl::ControlLayoutData* pLayout, const tools::Rectangle& rRect ) -- cgit