add simple_dragdrop feature

This commit is contained in:
Jinhao
2018-10-27 17:46:22 +08:00
parent ff9b90a766
commit 711dff56de
3 changed files with 182 additions and 115 deletions

View File

@@ -1111,7 +1111,7 @@ namespace detail
}
bool platform_spec::register_dragdrop(native_window_type wd, dragdrop_interface* ddrop)
bool platform_spec::register_dragdrop(native_window_type wd, x11_dragdrop_interface* ddrop)
{
platform_scope_guard lock;
if(0 != xdnd_.dragdrop.count(wd))
@@ -1121,13 +1121,11 @@ namespace detail
::XChangeProperty(display_, reinterpret_cast<Window>(wd), atombase_.xdnd_aware, XA_ATOM, sizeof(int) * 8,
PropModeReplace, reinterpret_cast<unsigned char*>(&dndver), 1);
auto & ref_drop = xdnd_.dragdrop[wd];
ref_drop.dragdrop = ddrop;
ref_drop.ref_count = 1;
xdnd_.dragdrop[wd] = ddrop;
return true;
}
dragdrop_interface* platform_spec::remove_dragdrop(native_window_type wd)
x11_dragdrop_interface* platform_spec::remove_dragdrop(native_window_type wd)
{
platform_scope_guard lock;
auto i = xdnd_.dragdrop.find(wd);
@@ -1135,13 +1133,9 @@ namespace detail
return nullptr;
auto ddrop = i->second;
if(ddrop.ref_count <= 1)
{
xdnd_.dragdrop.erase(i);
return ddrop.dragdrop;
}
--ddrop.ref_count;
return nullptr;
xdnd_.dragdrop.erase(i);
return ddrop;
}
//_m_msg_filter

View File

@@ -177,10 +177,13 @@ namespace detail
~platform_scope_guard();
};
class dragdrop_interface
class x11_dragdrop_interface
{
public:
virtual ~dragdrop_interface() = default;
virtual ~x11_dragdrop_interface() = default;
virtual void add_ref() = 0;
virtual std::size_t release() = 0;
};
class platform_spec
@@ -264,8 +267,8 @@ namespace detail
// the image object is release in remove() method.
const nana::paint::graphics& keep_window_icon(native_window_type, const nana::paint::image&);
bool register_dragdrop(native_window_type, dragdrop_interface*);
dragdrop_interface* remove_dragdrop(native_window_type);
bool register_dragdrop(native_window_type, x11_dragdrop_interface*);
x11_dragdrop_interface* remove_dragdrop(native_window_type);
private:
static int _m_msg_filter(XEvent&, msg_packet_tag&);
void _m_caret_routine();
@@ -323,13 +326,7 @@ namespace detail
Window wd_src;
nana::point pos;
struct refcount_dragdrop
{
dragdrop_interface* dragdrop{nullptr};
std::size_t ref_count{0};
};
std::map<native_window_type, refcount_dragdrop> dragdrop;
std::map<native_window_type, x11_dragdrop_interface*> dragdrop;
}xdnd_;
msg_dispatcher * msg_dispatcher_;