[英]Is it possible to drag data from a gtk app to other application under Windows? Like File Explorer?
I'm currently trying to make an application in gtk+3 for managing files.我目前正在尝试在 gtk+3 中创建一个用于管理文件的应用程序。 The goal is to have a file manager that is specialized in my own workflow, since I find Windows File Explorer for example too generic.
目标是拥有一个专门用于我自己的工作流程的文件管理器,因为我发现 Windows 文件资源管理器太通用了。
GTK of course supports drag and drop functionality, these are the things already set up and working: GTK 当然支持拖放功能,这些是已经设置和工作的东西:
But as the title suggests, dragging from my file listview and dropping into Windows File Explorer or any other application for that matter won't work, the mouse cursor keeps showing a 'blocked' symbol.但正如标题所暗示的,从我的文件列表视图中拖放到 Windows 文件资源管理器或任何其他与此相关的应用程序都不起作用,鼠标 cursor 一直显示“阻止”符号。
I also want to support Linux.我也想支持 Linux。 So I've tried this in a Manjaro vm that runs KDE Plasma.
所以我在运行 KDE Plasma 的 Manjaro 虚拟机中尝试了这个。 And dropping into the Dolphin file manager works fine.
并且放入 Dolphin 文件管理器工作正常。
On Windows, after some searching, I figured it was a security issue.在 Windows 上,经过一番搜索,我认为这是一个安全问题。 Maybe Windows doesn't allow 'untrusted' apps to drag and drop between other applications.
也许 Windows 不允许“不受信任”的应用程序在其他应用程序之间拖放。 But I made a release build, signed it with a trusted self-signed certificate and put my application it in C:\Program Files.
但是我做了一个发布版本,使用受信任的自签名证书对其进行签名,并将我的应用程序放在 C:\Program Files 中。 From there I run it, but it still does not work.
从那里我运行它,但它仍然不起作用。
This is the code that sets the selection data这是设置选择数据的代码
#define _BYTE 8
static void
drag_data_get_handl
(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data,
guint target_type, guint time, gpointer user_data)
{
const auto* unmarshalledUserdata = static_cast<DragAndDrop::GetDragData_Userdata*>(user_data);
const gchar *name = gtk_widget_get_name (widget);
const auto string_data = unmarshalledUserdata == nullptr ? "": unmarshalledUserdata->GetData();
g_print ("%s: drag_data_get_handl\n", name);
g_assert (selection_data != NULL);
g_print (" Sending ");
switch (target_type)
{
/* case TARGET_SOME_OBJECT:
* Serialize the object and send as a string of bytes.
* Pixbufs, (UTF-8) text, and URIs have their own convenience
* setter functions */
case TARGET_STRING:
g_print ("string: %s", string_data.c_str());
gtk_selection_data_set
(
selection_data,
gtk_selection_data_get_target(selection_data),
_BYTE,
(guchar*) string_data.c_str(), //for example file:///C:/Projects/tabspls_build_msvc/TabsPlsMain/TabsPlsMain.sln
static_cast<gint>(string_data.size())
);
break;
default:
/* Default to some a safe target instead of fail. */
g_assert_not_reached ();
}
g_print (".\n");
}
I don't know if this is necessary, but the entire project can be found on github .我不知道这是否有必要,但整个项目可以在 github 上找到。 This links to the revision that I am currently writing about.
这链接到我目前正在写的修订版。
I've been looking through the gtk sources and docs myself and I think I found the answer.我自己一直在查看 gtk 源和文档,我想我找到了答案。
For starters, the docs state that the OLE2 drag and drop protocol is not implemented.对于初学者, 文档state 未实现 OLE2 拖放协议。 This would be required to drag and drop between applications on Windows.
这将需要在 Windows 上的应用程序之间拖放。
So why then can my gtk app receive files but not send them under Windows?那么为什么我的 gtk 应用程序可以接收文件但不能在 Windows 下发送它们? The docs state that the WM_DROPFILES protocol is supported, I can confirm this protocol is chosen by calling
gdk_drag_context_get_protocol
on the context in my drop receive callback.支持 WM_DROPFILES 协议的文档 state 可以通过在我的 drop 接收回调的上下文中调用
gdk_drag_context_get_protocol
来确认选择了此协议。
So if I would like to support this in my own app, I would have to use WM_DROPFILES for sending data (I don't think this can be done throught the gtk library).因此,如果我想在自己的应用程序中支持这一点,我将不得不使用 WM_DROPFILES 来发送数据(我认为这不能通过 gtk 库来完成)。 Or I would need to implement my own OLE2 drag and drop separately from gtk.
或者我需要从 gtk 单独实现我自己的 OLE2 拖放。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.