diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2019-07-09 20:29:05 +0000 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2019-07-10 17:51:43 +0200 |
commit | f8f43e55ec4ae7e436a5043fe6f4bae7b39cc6ad (patch) | |
tree | 592bcb60a7861d0ab4f17fabeca822c8c635d092 /vcl/source | |
parent | 70c80d626493828cc40227de4cdcfb1842356069 (diff) |
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 <glogow@fbihome.de>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/treelist/transfer2.cxx | 41 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 69 |
2 files changed, 52 insertions, 58 deletions
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 <config_features.h> + #include <osl/mutex.hxx> #include <sot/exchange.hxx> #include <sot/storage.hxx> @@ -26,9 +28,12 @@ #include <vcl/svapp.hxx> #include <vcl/window.hxx> #include <comphelper/fileformat.h> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp> #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp> #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp> #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> +#include <com/sun/star/uno/DeploymentException.hpp> #include <svl/urlbmk.hxx> #include <vcl/inetimg.hxx> #include <vcl/imap.hxx> @@ -460,4 +465,40 @@ void TransferDataContainer::DragFinished( sal_Int8 nDropAction ) pImpl->aFinshedLnk.Call( nDropAction ); } +Reference<XClipboard> GetSystemClipboard() +{ + Reference<XClipboard> xClipboard; + try + { + xClipboard = css::datatransfer::clipboard::SystemClipboard::create( + comphelper::getProcessComponentContext()); + } + catch (DeploymentException const &) {} + return xClipboard; +} + +Reference<XClipboard> GetSystemPrimarySelection() +{ + Reference<XClipboard> xSelection; + 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"); + 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 <vcl/sysdata.hxx> #include <vcl/ptrstyle.hxx> #include <vcl/IDialogRenderable.hxx> +#include <vcl/transfer.hxx> #include <vcl/uitest/uiobject.hxx> #include <vcl/uitest/uitest.hxx> @@ -3273,68 +3274,20 @@ void Window::SetClipboard(Reference<XClipboard> 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<XClipboard*>(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<XClipboard*>(nullptr); + if (!mpWindowImpl->mpFrameData->mxSelection.is()) + mpWindowImpl->mpFrameData->mxSelection = GetSystemPrimarySelection(); + return mpWindowImpl->mpFrameData->mxSelection; } void Window::RecordLayoutData( vcl::ControlLayoutData* pLayout, const tools::Rectangle& rRect ) |