diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-01-27 10:16:39 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-01-27 13:15:00 +0000 |
commit | a5b4f6e456bfb735385e8d3d6945ea8f3be1ba94 (patch) | |
tree | af86e52f278beb9eeace70f24a6ef04acef7324b /vcl/inc | |
parent | 626702aa39798715fd252ae8f484233cae8a829f (diff) |
Resolves: tdf#93054 gtk3: implement drag and drop
Change-Id: Ib644ea36b8a9e68e023e465ef159b9a4890e5d37
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 27 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkinst.hxx | 46 |
2 files changed, 73 insertions, 0 deletions
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index 584a2ab96922..6c7058a6c784 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -40,6 +40,9 @@ #include "tools/link.hxx" #include <com/sun/star/awt/XTopWindow.hpp> +#include <com/sun/star/datatransfer/DataFlavor.hpp> +#include <com/sun/star/datatransfer/dnd/XDragSource.hpp> +#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> #include <list> #include <vector> @@ -55,6 +58,7 @@ typedef ::Window GdkNativeWindow; #define gdk_set_sm_client_id(i) gdk_x11_set_sm_client_id(i) #define gdk_window_foreign_new_for_display(a,b) gdk_x11_window_foreign_new_for_display(a,b) class GtkDropTarget; +class GtkDragSource; class GtkDnDTransferable; #endif @@ -209,6 +213,7 @@ class GtkSalFrame : public SalFrame long m_nHeightRequest; cairo_region_t* m_pRegion; GtkDropTarget* m_pDropTarget; + GtkDragSource* m_pDragSource; bool m_bInDrag; GtkDnDTransferable* m_pFormatConversionRequest; #else @@ -249,6 +254,13 @@ class GtkSalFrame : public SalFrame static void signalDragDropReceived(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint ttype, guint time, gpointer frame); static void signalDragLeave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer frame); + + static gboolean signalDragFailed(GtkWidget *widget, GdkDragContext *context, GtkDragResult result, gpointer frame); + static void signalDragDelete(GtkWidget *widget, GdkDragContext *context, gpointer frame); + static void signalDragEnd(GtkWidget *widget, GdkDragContext *context, gpointer frame); + static void signalDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData *data, guint info, + guint time, gpointer frame); + #if GTK_CHECK_VERSION(3,14,0) static void gestureSwipe(GtkGestureSwipe* gesture, gdouble velocity_x, gdouble velocity_y, gpointer frame); static void gestureLongPress(GtkGestureLongPress* gesture, gpointer frame); @@ -385,11 +397,26 @@ public: m_pDropTarget = nullptr; } + void registerDragSource(GtkDragSource* pDragSource) + { + assert(!m_pDragSource); + m_pDragSource = pDragSource; + } + + void deregisterDragSource(GtkDragSource* pDragSource) + { + assert(m_pDragSource == pDragSource); (void)pDragSource; + m_pDragSource = nullptr; + } + void SetFormatConversionRequest(GtkDnDTransferable *pRequest) { m_pFormatConversionRequest = pRequest; } + void startDrag(gint nButton, gint nDragOriginX, gint nDragOriginY, + GdkDragAction sourceActions, GtkTargetList* pTargetList); + #endif virtual ~GtkSalFrame(); diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx index a649f620e223..93a041b7982a 100644 --- a/vcl/inc/unx/gtk/gtkinst.hxx +++ b/vcl/inc/unx/gtk/gtkinst.hxx @@ -24,6 +24,7 @@ #include <unx/gensys.h> #include <headless/svpinst.hxx> #include <com/sun/star/datatransfer/DataFlavor.hpp> +#include <com/sun/star/datatransfer/dnd/XDragSource.hpp> #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -56,6 +57,8 @@ struct VclToGtkHelper { std::vector<css::datatransfer::DataFlavor> aInfoToFlavor; std::vector<GtkTargetEntry> FormatsToGtk(const css::uno::Sequence<css::datatransfer::DataFlavor> &rFormats); + void setSelectionData(const css::uno::Reference<css::datatransfer::XTransferable> &rTrans, + GtkSelectionData *selection_data, guint info); private: GtkTargetEntry makeGtkTargetEntry(const css::datatransfer::DataFlavor& rFlavor); }; @@ -123,6 +126,48 @@ public: void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde); void fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte); }; + +class GtkDragSource : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDragSource, + css::lang::XInitialization, + css::lang::XServiceInfo> +{ + osl::Mutex m_aMutex; + GtkSalFrame* m_pFrame; + css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> m_xListener; + css::uno::Reference<css::datatransfer::XTransferable> m_xTrans; + VclToGtkHelper m_aConversionHelper; +public: + GtkDragSource() : WeakComponentImplHelper( m_aMutex ) {} + virtual ~GtkDragSource(); + + // XDragSource + virtual sal_Bool SAL_CALL isDragImageSupported() throw(std::exception) override; + virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction) throw(std::exception) override; + virtual void SAL_CALL startDrag( + const css::datatransfer::dnd::DragGestureEvent& trigger, sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image, + const css::uno::Reference< css::datatransfer::XTransferable >& transferable, + const css::uno::Reference< css::datatransfer::dnd::XDragSourceListener >& listener) throw(std::exception) override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any >& rArguments) + throw (css::uno::Exception, std::exception) override; + void deinitialize(); + + OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException, std::exception) override; + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) + throw (css::uno::RuntimeException, std::exception) override; + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() + throw (css::uno::RuntimeException, std::exception) override; + + void dragFailed(); + void dragDelete(); + void dragEnd(GdkDragContext* context); + void dragDataGet(GtkSelectionData *data, guint info); +}; + #endif class GtkSalTimer; @@ -175,6 +220,7 @@ public: #if GTK_CHECK_VERSION(3,0,0) virtual css::uno::Reference< css::uno::XInterface > CreateClipboard( const css::uno::Sequence< css::uno::Any >& i_rArguments ) override; + virtual css::uno::Reference< css::uno::XInterface > CreateDragSource() override; virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget() override; #endif |