refactor arg_dropfiles with std::filesystem::path

This commit is contained in:
Jinhao
2019-03-03 07:07:58 +08:00
parent 71f57bbf92
commit f137f751c0
4 changed files with 12 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
/** /**
* Definition of General Events * Definition of General Events
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@@ -17,6 +17,7 @@
#include <nana/gui/basis.hpp> #include <nana/gui/basis.hpp>
#include "event_code.hpp" #include "event_code.hpp"
#include "internal_scope_guard.hpp" #include "internal_scope_guard.hpp"
#include "../../filesystem/filesystem.hpp"
#include <type_traits> #include <type_traits>
#include <functional> #include <functional>
#include <vector> #include <vector>
@@ -470,9 +471,9 @@ namespace nana
struct arg_dropfiles : public event_arg struct arg_dropfiles : public event_arg
{ {
::nana::window window_handle; ///< A handle to the event window ::nana::window window_handle; ///< A handle to the event window
::nana::point pos; ///< cursor position in the event window ::nana::point pos; ///< cursor position in the event window
std::vector<std::string> files; ///< external filenames std::vector<std::filesystem::path> files; ///< external filenames
}; };
struct arg_expose : public event_arg struct arg_expose : public event_arg

View File

@@ -1238,7 +1238,7 @@ namespace detail
0, AnyPropertyType, &type, &format, &len, 0, AnyPropertyType, &type, &format, &len,
&dummy_bytes_left, &data)) &dummy_bytes_left, &data))
{ {
auto files = new std::vector<std::string>; auto files = new std::vector<std::filesystem::path>;
std::stringstream ss(reinterpret_cast<char*>(data)); std::stringstream ss(reinterpret_cast<char*>(data));
while(true) while(true)
@@ -1258,7 +1258,7 @@ namespace detail
break; break;
} }
files->push_back(file); files->emplace_back(file);
} }
if(files->size()) if(files->size())

View File

@@ -3,6 +3,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <vector> #include <vector>
#include <nana/deploy.hpp> #include <nana/deploy.hpp>
#include <nana/filesystem/filesystem.hpp>
namespace nana namespace nana
{ {
@@ -29,7 +30,7 @@ namespace detail
Window window; Window window;
int x; int x;
int y; int y;
std::vector<std::string> * files; std::vector<std::filesystem::path> * files;
}mouse_drop; }mouse_drop;
}u; }u;
}; };

View File

@@ -1149,10 +1149,10 @@ namespace detail
std::unique_ptr<wchar_t[]> varbuf; std::unique_ptr<wchar_t[]> varbuf;
std::size_t bufsize = 0; std::size_t bufsize = 0;
unsigned size = ::DragQueryFile(drop, 0xFFFFFFFF, 0, 0); unsigned size = ::DragQueryFile(drop, 0xFFFFFFFF, nullptr, 0);
for(unsigned i = 0; i < size; ++i) for(unsigned i = 0; i < size; ++i)
{ {
unsigned reqlen = ::DragQueryFile(drop, i, 0, 0) + 1; unsigned reqlen = ::DragQueryFile(drop, i, nullptr, 0) + 1;
if(bufsize < reqlen) if(bufsize < reqlen)
{ {
varbuf.reset(new wchar_t[reqlen]); varbuf.reset(new wchar_t[reqlen]);
@@ -1160,8 +1160,7 @@ namespace detail
} }
::DragQueryFile(drop, i, varbuf.get(), reqlen); ::DragQueryFile(drop, i, varbuf.get(), reqlen);
dropfiles.files.emplace_back(varbuf.get());
dropfiles.files.emplace_back(to_utf8(varbuf.get()));
} }
while(msgwnd && (msgwnd->flags.dropable == false)) while(msgwnd && (msgwnd->flags.dropable == false))