fix compile errors under Linux

This commit is contained in:
Jinhao 2015-12-16 01:21:44 +08:00
parent c260eebbc3
commit 2ca11d4e25
21 changed files with 274 additions and 279 deletions

View File

@ -67,7 +67,8 @@ namespace nana
} }
}; };
typedef std::basic_string<wchar_t, casei_char_traits<wchar_t> > cistring; using cistring = std::basic_string<char, casei_char_traits<char>>;
using ciwstring = std::basic_string<wchar_t, casei_char_traits<wchar_t>>;
namespace detail namespace detail

View File

@ -20,7 +20,6 @@
#include <nana/config.hpp> #include <nana/config.hpp>
#include <nana/charset.hpp> #include <nana/charset.hpp>
//Implement workarounds for GCC/MinGW which version is below 4.8.2 //Implement workarounds for GCC/MinGW which version is below 4.8.2
#if defined(STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED) #if defined(STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED)
namespace std namespace std
@ -91,6 +90,7 @@ namespace nana
bool is_utf8(const char* str, unsigned len); bool is_utf8(const char* str, unsigned len);
void throw_not_utf8(const std::string& text); void throw_not_utf8(const std::string& text);
void throw_not_utf8(const char*, unsigned len); void throw_not_utf8(const char*, unsigned len);
void throw_not_utf8(const char*);
std::wstring utf8_cast(const std::string&); std::wstring utf8_cast(const std::string&);
std::string utf8_cast(const std::wstring&); std::string utf8_cast(const std::wstring&);
@ -105,7 +105,7 @@ namespace nana
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
std::string to_osmbstr(const std::string& text_utf8); std::string to_osmbstr(const std::string& text_utf8);
#else #else
std::string to_osmbstr(std::string text_utf8) std::string to_osmbstr(std::string text_utf8);
#endif #endif

View File

@ -1,12 +1,12 @@
/* /*
* A File Iterator Implementation * A File Iterator Implementation
* Copyright(C) 2003 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2015 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
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
* *
* @file: stdex/filesystem/file_iterator.hpp * @file: filesystem/file_iterator.hpp
* @description: * @description:
* file_iterator is a toolkit for applying each file and directory in a * file_iterator is a toolkit for applying each file and directory in a
* specified path. * specified path.
@ -39,7 +39,7 @@ namespace filesystem
#ifdef NANA_WINDOWS #ifdef NANA_WINDOWS
fileinfo(const WIN32_FIND_DATA& wfd); fileinfo(const WIN32_FIND_DATA& wfd);
#elif defined(NANA_POSIX) #elif defined(NANA_POSIX)
fileinfo(const nana::string& filename, const struct stat &); fileinfo(const std::string& filename, const struct stat &);
#endif #endif
::std::string name; ::std::string name;
@ -119,10 +119,10 @@ namespace filesystem
} }
value_ = value_type(wfd_); value_ = value_type(wfd_);
#elif defined(NANA_LINUX) || defined(NANA_MACOS) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
auto path = file_path; path_ = file_path;
if(path.size() && path.back() != '/') if(path_.size() && path_.back() != '/')
path += '/'; path_ += '/';
auto handle = opendir(path.c_str()); auto handle = opendir(path_.c_str());
end_ = true; end_ = true;
if(handle) if(handle)
@ -141,9 +141,9 @@ namespace filesystem
} }
struct stat fst; struct stat fst;
if(stat((path + dnt->d_name).c_str(), &fst) == 0) if(stat((path_ + dnt->d_name).c_str(), &fst) == 0)
{ {
value_ = value_type(nana::charset(dnt->d_name), fst); value_ = value_type(dnt->d_name, fst);
} }
else else
{ {
@ -226,6 +226,8 @@ namespace filesystem
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
WIN32_FIND_DATA wfd_; WIN32_FIND_DATA wfd_;
#else
std::string path_;
#endif #endif
std::shared_ptr<find_handle_t> find_ptr_; std::shared_ptr<find_handle_t> find_ptr_;

View File

@ -448,17 +448,16 @@ namespace filesystem
//bool create_directory(const path& p, error_code& ec) noexcept; //bool create_directory(const path& p, error_code& ec) noexcept;
bool create_directory(const path& p, const path& attributes); bool create_directory(const path& p, const path& attributes);
//bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept; //bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept;
bool create_directory(const nana::string& dir, bool & if_exist); bool create_directory(const std::wstring& p, bool & if_exist);
inline bool create_directory(const path& p, bool & if_exist) inline bool create_directory(const path& p, bool & if_exist)
{ {
return create_directory(p.filename(), if_exist); return create_directory(p.filename(), if_exist);
}; };
bool modified_file_time(const std::wstring& file, struct tm&);
bool modified_file_time(const nana::string& file, struct tm&);
nana::string path_user(); path path_user();
path current_path(); path current_path();
@ -468,14 +467,14 @@ namespace filesystem
//nana::string path_current(); //nana::string path_current();
//bool remove(const path& p); //bool remove(const path& p);
//bool remove(const path& p, error_code& ec) noexcept; //bool remove(const path& p, error_code& ec) noexcept;
bool rmfile(const char* file); bool rmfile(const path& p);
//uintmax_t remove_all(const path& p); //uintmax_t remove_all(const path& p);
//uintmax_t remove_all(const path& p, error_code& ec) noexcept; //uintmax_t remove_all(const path& p, error_code& ec) noexcept;
bool rmdir(const char* dir, bool fails_if_not_empty);
bool rmdir(const wchar_t* dir, bool fails_if_not_empty); bool rmdir(const path& p, bool fails_if_not_empty);
template<typename CharType> template<typename CharType>
std::basic_string<CharType> parent_path(const std::basic_string<CharType>& path) std::basic_string<CharType> parent_path(const std::basic_string<CharType>& path)

View File

@ -28,10 +28,10 @@ namespace filesystem
long long filesize(const nana::string& file); long long filesize(const nana::string& file);
bool mkdir(const ::std::string& dir, bool & if_exist); bool mkdir(const ::std::string& dir, bool & if_exist);
bool modified_file_time(const nana::string& file, struct tm&); bool modified_file_time(const ::std::string& file, struct tm&);
nana::string path_user(); std::wstring path_user();
nana::string path_current(); std::wstring path_current();
bool rmfile(const char* file_utf8); bool rmfile(const char* file_utf8);
bool rmdir(const char* dir, bool fails_if_not_empty); bool rmdir(const char* dir, bool fails_if_not_empty);
@ -59,6 +59,7 @@ namespace filesystem
std::string text_; std::string text_;
#endif #endif
}; };
}//end namespace filesystem }//end namespace filesystem
}//end namespace nana }//end namespace nana

View File

@ -155,8 +155,9 @@ namespace nana
: public widget_object<category::widget_tag, drawerbase::categorize::trigger, drawerbase::categorize::categorize_events<T>> : public widget_object<category::widget_tag, drawerbase::categorize::trigger, drawerbase::categorize::categorize_events<T>>
{ {
public: public:
typedef T value_type; ///< The type of objects stored using native_string_type = widget::native_string_type;
typedef drawerbase::categorize::renderer renderer; ///< The interface for user-defined renderer. using value_type = T; ///< The type of objects stored
using renderer = drawerbase::categorize::renderer; ///< The interface for user-defined renderer.
categorize() categorize()
{ {
@ -177,13 +178,13 @@ namespace nana
categorize(window wd, const std::string& text_utf8, bool visible = true) categorize(window wd, const std::string& text_utf8, bool visible = true)
: categorize(wd, ::nana::rectangle(), visible) : categorize(wd, ::nana::rectangle(), visible)
{ {
this->caption(text); this->caption(text_utf8);
} }
categorize(window wd, const char* text_utf8, bool visible = true) categorize(window wd, const char* text_utf8, bool visible = true)
: categorize(wd, ::nana::rectangle(), visible) : categorize(wd, ::nana::rectangle(), visible)
{ {
this->caption(text); this->caption(text_utf8);
} }
categorize(window wd, const std::wstring& text, bool visible = true) categorize(window wd, const std::wstring& text, bool visible = true)

View File

@ -14,6 +14,7 @@
#include <nana/deploy.hpp> #include <nana/deploy.hpp>
#include <cstdlib> #include <cstdlib>
#include <cstring> //std::strlen
#include <stdexcept> #include <stdexcept>
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
@ -472,6 +473,13 @@ namespace nana
throw std::invalid_argument("The text is not encoded in UTF8"); throw std::invalid_argument("The text is not encoded in UTF8");
} }
void throw_not_utf8(const char* text)
{
if (!is_utf8(text, std::strlen(text)))
throw std::invalid_argument("The text is not encoded in UTF8");
}
std::wstring utf8_cast(const std::string& text) std::wstring utf8_cast(const std::string& text)
{ {
return ::nana::charset(text, ::nana::unicode::utf8); return ::nana::charset(text, ::nana::unicode::utf8);

View File

@ -555,12 +555,11 @@ namespace detail
font_ptr_t ref; font_ptr_t ref;
#if 1 //Xft #if 1 //Xft
if(0 == name || *name == 0) if(0 == name || *name == 0)
name = STR("*"); name = "*";
std::string nmstr = nana::charset(name);
XftFont* handle = 0; XftFont* handle = 0;
std::stringstream ss; std::stringstream ss;
ss<<nmstr<<"-"<<(height ? height : 10); ss<<name<<"-"<<(height ? height : 10);
XftPattern * pat = ::XftNameParse(ss.str().c_str()); XftPattern * pat = ::XftNameParse(ss.str().c_str());
XftResult res; XftResult res;
XftPattern * match_pat = ::XftFontMatch(display_, ::XDefaultScreen(display_), pat, &res); XftPattern * match_pat = ::XftFontMatch(display_, ::XDefaultScreen(display_), pat, &res);
@ -1216,7 +1215,7 @@ namespace detail
0, AnyPropertyType, &type, &format, &len, 0, AnyPropertyType, &type, &format, &len,
&dummy_bytes_left, &data)) &dummy_bytes_left, &data))
{ {
std::vector<nana::string> * files = new std::vector<nana::string>; auto files = new std::vector<std::string>;
std::stringstream ss(reinterpret_cast<char*>(data)); std::stringstream ss(reinterpret_cast<char*>(data));
while(true) while(true)
{ {
@ -1235,7 +1234,7 @@ namespace detail
break; break;
} }
files->push_back(nana::charset(file)); files->push_back(file);
} }
if(files->size()) if(files->size())
{ {
@ -1244,6 +1243,8 @@ namespace detail
msg.u.mouse_drop.y = self.xdnd_.pos.y; msg.u.mouse_drop.y = self.xdnd_.pos.y;
msg.u.mouse_drop.files = files; msg.u.mouse_drop.files = files;
} }
else
delete files;
accepted = true; accepted = true;
::XFree(data); ::XFree(data);

View File

@ -327,7 +327,7 @@ namespace nana {
#endif #endif
} }
bool modified_file_time(const nana::string& file, struct tm& t) bool modified_file_time(const std::wstring& file, struct tm& t)
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
WIN32_FILE_ATTRIBUTE_DATA attr; WIN32_FILE_ATTRIBUTE_DATA attr;
@ -361,17 +361,17 @@ namespace nana {
return false; return false;
} }
bool create_directory(const nana::string& path, bool & if_exist) bool create_directory(const std::wstring& path, bool & if_exist)
{ {
if_exist = false; if_exist = false;
if (path.size() == 0) return false; if (path.size() == 0) return false;
nana::string root; std::wstring root;
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
if (path.size() > 3 && path[1] == L':') if (path.size() > 3 && path[1] == L':')
root = path.substr(0, 3); root = path.substr(0, 3);
#elif defined(NANA_LINUX) || defined(NANA_MACOS) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if (path[0] == STR('/')) if (path[0] == L'/')
root = '/'; root = '/';
#endif #endif
bool mkstat = false; bool mkstat = false;
@ -412,107 +412,86 @@ namespace nana {
return mkstat; return mkstat;
} }
bool rmfile(const nana::char_t* file)
{
#if defined(NANA_WINDOWS)
bool ret = false;
if (file)
{
ret = (::DeleteFile(file) == TRUE);
if (!ret)
ret = (ERROR_FILE_NOT_FOUND == ::GetLastError());
}
return ret; bool rmfile(const path& p)
#elif defined(NANA_LINUX) || defined(NANA_MACOS) {
if (std::remove(static_cast<std::string>(nana::charset(file)).c_str())) if(p.empty())
return false;
#if defined(NANA_WINDOWS)
if (FALSE == ::DeleteFileW(p.c_str()))
return (ERROR_FILE_NOT_FOUND == ::GetLastError());
return true;
#elif defined(NANA_POSIX)
if (std::remove(p.c_str()))
return (errno == ENOENT); return (errno == ENOENT);
return true; return true;
#endif #endif
} }
bool rmdir(const char* dir_utf8, bool fails_if_not_empty)
bool rmdir(const path& p, bool fails_if_not_empty)
{ {
bool ret = false; if(p.empty())
if (dir_utf8) return false;
{
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
auto dir = utf8_cast(dir_utf8); if(FALSE != ::RemoveDirectoryW(p.c_str()))
ret = (::RemoveDirectory(dir.c_str()) == TRUE); return true;
if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY))
ret = detail::rm_dir_recursive(dir.c_str()); if(!fails_if_not_empty && (ERROR_DIR_NOT_EMPTY == ::GetLastError()))
#elif defined(NANA_LINUX) || defined(NANA_MACOS) return detail::rm_dir_recursive(p.c_str());
if (::rmdir(dir_utf8))
{ return false;
if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) #elif defined(NANA_POSIX)
ret = detail::rm_dir_recursive(dir); if(::rmdir(p.c_str()))
} {
else if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY))
ret = true; return detail::rm_dir_recursive(p.c_str());
#endif
return false;
} }
return ret; return true;
#endif
} }
bool rmdir(const wchar_t* dir, bool fails_if_not_empty) path path_user()
{
bool ret = false;
if (dir)
{
#if defined(NANA_WINDOWS)
ret = (::RemoveDirectory(dir) == TRUE);
if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY))
ret = detail::rm_dir_recursive(dir);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
if (::rmdir(utf8_cast(dir).c_str()))
{
if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY))
ret = detail::rm_dir_recursive(dir);
}
else
ret = true;
#endif
}
return ret;
}
nana::string path_user()
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
nana::char_t path[MAX_PATH]; wchar_t pstr[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path))) if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, pstr)))
return path; return pstr;
#elif defined(NANA_LINUX) || defined(NANA_MACOS) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
const char * s = ::getenv("HOME"); const char * pstr = ::getenv("HOME");
if (s) if (pstr)
return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); return pstr;
#endif #endif
return nana::string(); return path();
} }
path current_path() path current_path()
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
nana::char_t buf[MAX_PATH]; wchar_t buf[MAX_PATH];
DWORD len = ::GetCurrentDirectory(MAX_PATH, buf); DWORD len = ::GetCurrentDirectoryW(MAX_PATH, buf);
if (len) if (len)
{ {
if (len > MAX_PATH) if (len > MAX_PATH)
{ {
nana::char_t * p = new nana::char_t[len + 1]; wchar_t * p = new wchar_t[len + 1];
::GetCurrentDirectory(len + 1, p); ::GetCurrentDirectoryW(len + 1, p);
nana::string s = p; std::wstring s = p;
delete[] p; delete[] p;
return s; return s;
} }
return nana::string(buf); return buf;
} }
#elif defined(NANA_LINUX) || defined(NANA_MACOS) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
const char * s = ::getenv("PWD"); auto pstr = ::getenv("PWD");
if (s) if (pstr)
return static_cast<nana::string>(nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8)); return pstr;
#endif #endif
return nana::string(); return path();
} }
}//end namespace filesystem }//end namespace filesystem
} //end namespace experimental } //end namespace experimental

View File

@ -257,11 +257,11 @@ namespace filesystem
#endif #endif
} }
bool modified_file_time(const nana::string& file, struct tm& t) bool modified_file_time(const ::std::string& file, struct tm& t)
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
WIN32_FILE_ATTRIBUTE_DATA attr; WIN32_FILE_ATTRIBUTE_DATA attr;
if(::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &attr)) if(::GetFileAttributesExW(to_nstring(file).c_str(), GetFileExInfoStandard, &attr))
{ {
FILETIME local_file_time; FILETIME local_file_time;
if(::FileTimeToLocalFileTime(&attr.ftLastWriteTime, &local_file_time)) if(::FileTimeToLocalFileTime(&attr.ftLastWriteTime, &local_file_time))
@ -282,7 +282,7 @@ namespace filesystem
} }
#elif defined(NANA_LINUX) || defined(NANA_MACOS) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat attr; struct stat attr;
if(0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &attr)) if(0 == ::stat(file.c_str(), &attr))
{ {
t = *(::localtime(&attr.st_ctime)); t = *(::localtime(&attr.st_ctime));
return true; return true;
@ -301,7 +301,7 @@ namespace filesystem
if(path.size() > 3 && path[1] == ':') if(path.size() > 3 && path[1] == ':')
root = path.substr(0, 3); root = path.substr(0, 3);
#elif defined(NANA_LINUX) || defined(NANA_MACOS) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(path[0] == STR('/')) if(path[0] == '/')
root = '/'; root = '/';
#endif #endif
bool mkstat = false; bool mkstat = false;

View File

@ -1096,7 +1096,7 @@ namespace nana{
::XSetWMName(restrict::spec.open_display(), reinterpret_cast<Window>(wd), &name); ::XSetWMName(restrict::spec.open_display(), reinterpret_cast<Window>(wd), &name);
::XChangeProperty(restrict::spec.open_display(), reinterpret_cast<Window>(wd), ::XChangeProperty(restrict::spec.open_display(), reinterpret_cast<Window>(wd),
restrict::spec.atombase().net_wm_name, restrict::spec.atombase().utf8_string, 8, restrict::spec.atombase().net_wm_name, restrict::spec.atombase().utf8_string, 8,
PropModeReplace, reinterpret_cast<unsigned char*>(text), mbstr.size()); PropModeReplace, reinterpret_cast<unsigned char*>(text), title.size());
#endif #endif
} }

View File

@ -38,16 +38,16 @@ namespace nana
{ {
struct item_fs struct item_fs
{ {
nana::string name; std::string name;
::tm modified_time; ::tm modified_time;
bool directory; bool directory;
nana::long_long_t bytes; nana::long_long_t bytes;
friend listbox::iresolver& operator>>(listbox::iresolver& ires, item_fs& m) friend listbox::iresolver& operator>>(listbox::iresolver& ires, item_fs& m)
{ {
nana::string type; std::wstring type;
ires>>m.name>>type>>type; ires>>m.name>>type>>type;
m.directory = (type == STR("Directory")); m.directory = (type == L"Directory");
return ires; return ires;
} }
@ -65,16 +65,16 @@ namespace nana
ores<<item.name<<tm.str(); ores<<item.name<<tm.str();
if(!item.directory) if(!item.directory)
{ {
auto pos = item.name.find_last_of(STR('.')); auto pos = item.name.find_last_of('.');
if(pos != item.name.npos && (pos + 1 < item.name.size())) if(pos != item.name.npos && (pos + 1 < item.name.size()))
ores<<item.name.substr(pos + 1); ores<<item.name.substr(pos + 1);
else else
ores<<STR("File"); ores<<L"File";
ores<<_m_trans(item.bytes); ores<<_m_trans(item.bytes);
} }
else else
ores<<STR("Directory"); ores<<L"Directory";
return ores; return ores;
} }
@ -87,9 +87,9 @@ namespace nana
return ss; return ss;
} }
static nana::string _m_trans(std::size_t bytes) static std::string _m_trans(std::size_t bytes)
{ {
const nana::char_t * ustr[] = {STR(" KB"), STR(" MB"), STR(" GB"), STR(" TB")}; const char * ustr[] = {" KB", " MB", " GB", " TB"};
std::stringstream ss; std::stringstream ss;
if(bytes >= 1024) if(bytes >= 1024)
{ {
@ -108,10 +108,11 @@ namespace nana
if(pos + 2 < s.size()) if(pos + 2 < s.size())
s.erase(pos + 2); s.erase(pos + 2);
} }
return static_cast<nana::string>(nana::charset(s)) + ustr[uid];
return s + ustr[uid];
} }
ss<<bytes<<" Bytes"; ss<<bytes<<" Bytes";
return nana::charset(ss.str()); return ss.str();
} }
}; };
@ -131,29 +132,29 @@ namespace nana
typedef treebox::item_proxy item_proxy; typedef treebox::item_proxy item_proxy;
public: public:
filebox_implement(window owner, bool io_read, const nana::string& title) filebox_implement(window owner, bool io_read, const std::string& title)
: form(owner, API::make_center(owner, 630, 440)), io_read_(io_read) : form(owner, API::make_center(owner, 630, 440)), io_read_(io_read)
{ {
path_.create(*this); path_.create(*this);
path_.splitstr(STR("/")); path_.splitstr("/");
path_.events().selected.connect_unignorable([this](const arg_categorize<int>&) path_.events().selected.connect_unignorable([this](const arg_categorize<int>&)
{ {
auto path = path_.caption(); auto path = path_.caption();
auto root = path.substr(0, path.find(STR('/'))); auto root = path.substr(0, path.find('/'));
if(root == STR("HOME")) if(root == "HOME")
path.replace(0, 4, nana::filesystem::path_user()); path.replace(0, 4, to_nstring(nana::filesystem::path_user()));
else if(root == STR("FILESYSTEM")) else if(root == "FILESYSTEM")
path.erase(0, 10); path.erase(0, 10);
else else
throw std::runtime_error("Nana.GUI.Filebox: Wrong categorize path"); throw std::runtime_error("Nana.GUI.Filebox: Wrong categorize path");
if(path.size() == 0) path = STR("/"); if(path.size() == 0) path = "/";
_m_load_cat_path(path); _m_load_cat_path(path);
}); });
filter_.create(*this); filter_.create(*this);
filter_.multi_lines(false); filter_.multi_lines(false);
filter_.tip_string(STR("Filter")); filter_.tip_string("Filter");
filter_.events().key_release.connect_unignorable([this](const arg_keyboard&) filter_.events().key_release.connect_unignorable([this](const arg_keyboard&)
{ {
@ -161,23 +162,23 @@ namespace nana
}); });
btn_folder_.create(*this); btn_folder_.create(*this);
btn_folder_.caption(STR("&New Folder")); btn_folder_.caption("&New Folder");
btn_folder_.events().click.connect_unignorable([this](const arg_click&) btn_folder_.events().click.connect_unignorable([this](const arg_click&)
{ {
form fm(this->handle(), API::make_center(*this, 300, 35)); form fm(this->handle(), API::make_center(*this, 300, 35));
fm.caption(STR("Name the new folder")); fm.caption("Name the new folder");
textbox folder(fm, nana::rectangle(5, 5, 160, 25)); textbox folder(fm, nana::rectangle(5, 5, 160, 25));
folder.multi_lines(false); folder.multi_lines(false);
button btn(fm, nana::rectangle(170, 5, 60, 25)); button btn(fm, nana::rectangle(170, 5, 60, 25));
btn.caption(STR("Create")); btn.caption("Create");
btn.events().click.connect_unignorable(folder_creator(*this, fm, folder)); btn.events().click.connect_unignorable(folder_creator(*this, fm, folder));
button btn_cancel(fm, nana::rectangle(235, 5, 60, 25)); button btn_cancel(fm, nana::rectangle(235, 5, 60, 25));
btn_cancel.caption(STR("Cancel")); btn_cancel.caption("Cancel");
btn_cancel.events().click.connect_unignorable([&fm](const arg_click&) btn_cancel.events().click.connect_unignorable([&fm](const arg_click&)
{ {
@ -189,17 +190,17 @@ namespace nana
tree_.create(*this); tree_.create(*this);
ls_file_.create(*this); ls_file_.create(*this);
ls_file_.append_header(STR("Name"), 190); ls_file_.append_header("Name", 190);
ls_file_.append_header(STR("Modified"), 145); ls_file_.append_header("Modified", 145);
ls_file_.append_header(STR("Type"), 80); ls_file_.append_header("Type", 80);
ls_file_.append_header(STR("Size"), 70); ls_file_.append_header("Size", 70);
auto fn_sel_file = [this](const arg_mouse& arg){ auto fn_sel_file = [this](const arg_mouse& arg){
_m_sel_file(arg); _m_sel_file(arg);
}; };
ls_file_.events().dbl_click.connect_unignorable(fn_sel_file); ls_file_.events().dbl_click.connect_unignorable(fn_sel_file);
ls_file_.events().mouse_down.connect_unignorable(fn_sel_file); ls_file_.events().mouse_down.connect_unignorable(fn_sel_file);
ls_file_.set_sort_compare(0, [](const nana::string& a, nana::any* fs_a, const nana::string& b, nana::any* fs_b, bool reverse) -> bool ls_file_.set_sort_compare(0, [](const std::string& a, nana::any* fs_a, const std::string& b, nana::any* fs_b, bool reverse) -> bool
{ {
int dira = fs_a->get<item_fs>()->directory ? 1 : 0; int dira = fs_a->get<item_fs>()->directory ? 1 : 0;
int dirb = fs_b->get<item_fs>()->directory ? 1 : 0; int dirb = fs_b->get<item_fs>()->directory ? 1 : 0;
@ -211,8 +212,8 @@ namespace nana
while(true) while(true)
{ {
std::size_t pos_a = a.find_first_of(STR("0123456789"), seek_a); std::size_t pos_a = a.find_first_of("0123456789", seek_a);
std::size_t pos_b = b.find_first_of(STR("0123456789"), seek_b); std::size_t pos_b = b.find_first_of("0123456789", seek_b);
if((pos_a != a.npos) && (pos_a == pos_b)) if((pos_a != a.npos) && (pos_a == pos_b))
{ {
@ -222,11 +223,11 @@ namespace nana
if(text_a != text_b) if(text_a != text_b)
return (reverse ? text_a > text_b : text_a < text_b); return (reverse ? text_a > text_b : text_a < text_b);
std::size_t end_a = a.find_first_not_of(STR("0123456789"), pos_a + 1); std::size_t end_a = a.find_first_not_of("0123456789", pos_a + 1);
std::size_t end_b = b.find_first_not_of(STR("0123456789"), pos_b + 1); std::size_t end_b = b.find_first_not_of("0123456789", pos_b + 1);
nana::string num_a = a.substr(pos_a, end_a != a.npos ? end_a - pos_a : a.npos); auto num_a = a.substr(pos_a, end_a != a.npos ? end_a - pos_a : a.npos);
nana::string num_b = b.substr(pos_b, end_b != b.npos ? end_b - pos_b : b.npos); auto num_b = b.substr(pos_b, end_b != b.npos ? end_b - pos_b : b.npos);
if(num_a != num_b) if(num_a != num_b)
{ {
@ -253,7 +254,7 @@ namespace nana
return (reverse ? cia > cib : cia < cib); return (reverse ? cia > cib : cia < cib);
return (reverse ? cia.substr(seek_a) > cib.substr(seek_b) : cia.substr(seek_a) < cib.substr(seek_b)); return (reverse ? cia.substr(seek_a) > cib.substr(seek_b) : cia.substr(seek_a) < cib.substr(seek_b));
}); });
ls_file_.set_sort_compare(2, [](const nana::string& a, nana::any* anyptr_a, const nana::string& b, nana::any* anyptr_b, bool reverse) -> bool ls_file_.set_sort_compare(2, [](const std::string& a, nana::any* anyptr_a, const std::string& b, nana::any* anyptr_b, bool reverse) -> bool
{ {
int dir1 = anyptr_a->get<item_fs>()->directory ? 1 : 0; int dir1 = anyptr_a->get<item_fs>()->directory ? 1 : 0;
int dir2 = anyptr_b->get<item_fs>()->directory ? 1 : 0; int dir2 = anyptr_b->get<item_fs>()->directory ? 1 : 0;
@ -262,7 +263,7 @@ namespace nana
return (reverse ? a > b : a < b); return (reverse ? a > b : a < b);
}); });
ls_file_.set_sort_compare(3, [this](const nana::string&, nana::any* anyptr_a, const nana::string&, nana::any* anyptr_b, bool reverse) -> bool ls_file_.set_sort_compare(3, [this](const std::string&, nana::any* anyptr_a, const std::string&, nana::any* anyptr_b, bool reverse) -> bool
{ {
item_fs * fsa = anyptr_a->get<item_fs>(); item_fs * fsa = anyptr_a->get<item_fs>();
item_fs * fsb = anyptr_b->get<item_fs>(); item_fs * fsb = anyptr_b->get<item_fs>();
@ -270,7 +271,7 @@ namespace nana
}); });
lb_file_.create(*this); lb_file_.create(*this);
lb_file_.caption(STR("File:")); lb_file_.caption("File:");
tb_file_.create(*this); tb_file_.create(*this);
tb_file_.multi_lines(false); tb_file_.multi_lines(false);
@ -286,14 +287,14 @@ namespace nana
cb_types_.events().selected.connect_unignorable([this](const arg_combox&){ _m_list_fs(); }); cb_types_.events().selected.connect_unignorable([this](const arg_combox&){ _m_list_fs(); });
btn_ok_.create(*this); btn_ok_.create(*this);
btn_ok_.caption(STR("&OK")); btn_ok_.caption("&OK");
btn_ok_.events().click.connect_unignorable([this](const arg_click&) btn_ok_.events().click.connect_unignorable([this](const arg_click&)
{ {
_m_ok(); _m_ok();
}); });
btn_cancel_.create(*this); btn_cancel_.create(*this);
btn_cancel_.caption(STR("&Cancel")); btn_cancel_.caption("&Cancel");
btn_cancel_.events().click.connect_unignorable([this](const arg_click&) btn_cancel_.events().click.connect_unignorable([this](const arg_click&)
{ {
@ -305,25 +306,25 @@ namespace nana
_m_init_tree(); _m_init_tree();
if(0 == title.size()) if(0 == title.size())
caption(io_read ? STR("Open") : STR("Save As")); caption(io_read ? "Open" : "Save As");
else else
caption(title); caption(title);
} }
void def_extension(const nana::string& ext) void def_extension(const std::string& ext)
{ {
def_ext_ = ext; def_ext_ = ext;
} }
void load_fs(const nana::string& init_path, const nana::string& init_file) void load_fs(const std::string& init_path, const std::string& init_file)
{ {
//Simulate the behavior like Windows7's lpstrInitialDir(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx) //Simulate the behavior like Windows7's lpstrInitialDir(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx)
//Phase 1 //Phase 1
nana::string dir; std::string dir;
auto pos = init_file.find_last_of(STR("\\/")); auto pos = init_file.find_last_of("\\/");
nana::string file_with_path_removed = (pos != init_file.npos ? init_file.substr(pos + 1) : init_file); auto file_with_path_removed = (pos != init_file.npos ? init_file.substr(pos + 1) : init_file);
if(saved_init_path != init_path) if(saved_init_path != init_path)
{ {
@ -343,29 +344,29 @@ namespace nana
else else
dir = saved_selected_path; dir = saved_selected_path;
_m_load_cat_path(dir.size() ? dir : nana::filesystem::path_user()); _m_load_cat_path(dir.size() ? dir : to_nstring(nana::filesystem::path_user()));
tb_file_.caption(file_with_path_removed); tb_file_.caption(file_with_path_removed);
} }
void add_filter(const nana::string& desc, const nana::string& type) void add_filter(const std::string& desc, const std::string& type)
{ {
std::size_t i = cb_types_.the_number_of_options(); std::size_t i = cb_types_.the_number_of_options();
cb_types_.push_back(desc); cb_types_.push_back(desc);
if(0 == i) if(0 == i)
cb_types_.option(0); cb_types_.option(0);
std::vector<nana::string> v; std::vector<std::string> v;
std::size_t beg = 0; std::size_t beg = 0;
while(true) while(true)
{ {
auto pos = type.find(STR(';'), beg); auto pos = type.find(';', beg);
auto ext = type.substr(beg, pos == type.npos ? type.npos : pos - beg); auto ext = type.substr(beg, pos == type.npos ? type.npos : pos - beg);
auto dot = ext.find(STR('.')); auto dot = ext.find('.');
if((dot != ext.npos) && (dot + 1 < ext.size())) if((dot != ext.npos) && (dot + 1 < ext.size()))
{ {
ext.erase(0, dot + 1); ext.erase(0, dot + 1);
if(ext == STR("*")) if(ext == "*")
{ {
v.clear(); v.clear();
break; break;
@ -381,12 +382,12 @@ namespace nana
cb_types_.anyobj(i, v); cb_types_.anyobj(i, v);
} }
bool file(nana::string& fs) const bool file(std::string& fs) const
{ {
if(selection_.type == kind::none) if(selection_.type == kind::none)
return false; return false;
auto pos = selection_.target.find_last_of(STR("\\/")); auto pos = selection_.target.find_last_of("\\/");
if(pos != selection_.target.npos) if(pos != selection_.target.npos)
saved_selected_path = selection_.target.substr(0, pos); saved_selected_path = selection_.target.substr(0, pos);
else else
@ -423,13 +424,13 @@ namespace nana
//The path in linux is starting with the character '/', the name of root key should be //The path in linux is starting with the character '/', the name of root key should be
//"FS.HOME", "FS.ROOT". Because a key of the tree widget should not be '/' //"FS.HOME", "FS.ROOT". Because a key of the tree widget should not be '/'
nodes_.home = tree_.insert(STR("FS.HOME"), STR("Home")); nodes_.home = tree_.insert("FS.HOME", "Home");
nodes_.home.value(kind::filesystem); nodes_.home.value(kind::filesystem);
nodes_.filesystem = tree_.insert(STR("FS.ROOT"), STR("Filesystem")); nodes_.filesystem = tree_.insert("FS.ROOT", "Filesystem");
nodes_.filesystem.value(kind::filesystem); nodes_.filesystem.value(kind::filesystem);
file_iterator end; file_iterator end;
for(file_iterator i(path_user()); i != end; ++i) for(file_iterator i(to_nstring(path_user())); i != end; ++i)
{ {
if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue; if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue;
@ -441,7 +442,7 @@ namespace nana
} }
} }
for(file_iterator i(STR("/")); i != end; ++i) for(file_iterator i("/"); i != end; ++i)
{ {
if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue; if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue;
@ -462,33 +463,33 @@ namespace nana
{ {
if(arg.operated && (arg.item.value<kind::t>() == kind::filesystem)) if(arg.operated && (arg.item.value<kind::t>() == kind::filesystem))
{ {
auto path = tree_.make_key_path(arg.item, STR("/")) + STR("/"); auto path = tree_.make_key_path(arg.item, "/") + "/";
_m_resolute_path(path); _m_resolute_path(path);
_m_load_cat_path(path); _m_load_cat_path(path);
} }
}); });
} }
nana::string _m_resolute_path(nana::string& path) std::string _m_resolute_path(std::string& path)
{ {
auto pos = path.find(STR('/')); auto pos = path.find('/');
if(pos != path.npos) if(pos != path.npos)
{ {
auto begstr = path.substr(0, pos); auto begstr = path.substr(0, pos);
if(begstr == STR("FS.HOME")) if(begstr == "FS.HOME")
path.replace(0, 7, nana::filesystem::path_user()); path.replace(0, 7, to_nstring(nana::filesystem::path_user()));
else else
path.erase(0, pos); path.erase(0, pos);
return begstr; return begstr;
} }
return nana::string(); return std::string();
} }
void _m_load_path(const nana::string& path) void _m_load_path(const std::string& path)
{ {
addr_.filesystem = path; addr_.filesystem = path;
if(addr_.filesystem.size() && addr_.filesystem[addr_.filesystem.size() - 1] != STR('/')) if(addr_.filesystem.size() && addr_.filesystem[addr_.filesystem.size() - 1] != '/')
addr_.filesystem += STR('/'); addr_.filesystem += '/';
file_container_.clear(); file_container_.clear();
@ -497,7 +498,7 @@ namespace nana
file_iterator end; file_iterator end;
for(file_iterator i(path); i != end; ++i) for(file_iterator i(path); i != end; ++i)
{ {
if((i->name.size() == 0) || (i->name[0] == STR('.'))) if((i->name.size() == 0) || (i->name[0] == '.'))
continue; continue;
item_fs m; item_fs m;
m.name = i->name; m.name = i->name;
@ -522,32 +523,32 @@ namespace nana
std::sort(file_container_.begin(), file_container_.end(), pred_sort_fs()); std::sort(file_container_.begin(), file_container_.end(), pred_sort_fs());
} }
void _m_load_cat_path(nana::string path) void _m_load_cat_path(std::string path)
{ {
if((path.size() == 0) || (path[path.size() - 1] != STR('/'))) if((path.size() == 0) || (path[path.size() - 1] != '/'))
path += STR('/'); path += '/';
auto beg_node = tree_.selected(); auto beg_node = tree_.selected();
while(!beg_node.empty() && (beg_node != nodes_.home) && (beg_node != nodes_.filesystem)) while(!beg_node.empty() && (beg_node != nodes_.home) && (beg_node != nodes_.filesystem))
beg_node = beg_node.owner(); beg_node = beg_node.owner();
auto head = nana::filesystem::path_user(); auto head = to_nstring(nana::filesystem::path_user());
if(path.size() >= head.size() && (path.substr(0, head.size()) == head)) if(path.size() >= head.size() && (path.substr(0, head.size()) == head))
{//This is HOME {//This is HOME
path_.caption(STR("HOME")); path_.caption("HOME");
if(beg_node != nodes_.home) if(beg_node != nodes_.home)
nodes_.home->select(true); nodes_.home->select(true);
} }
else else
{ //Redirect to '/' { //Redirect to '/'
path_.caption(STR("FILESYSTEM")); path_.caption("FILESYSTEM");
if(beg_node != nodes_.filesystem) if(beg_node != nodes_.filesystem)
nodes_.filesystem->select(true); nodes_.filesystem->select(true);
head.clear(); head.clear();
} }
if(head.size() == 0 || head[head.size() - 1] != STR('/')) if(head.size() == 0 || head[head.size() - 1] != '/')
head += STR('/'); head += '/';
nana::filesystem::file_iterator end; nana::filesystem::file_iterator end;
for(nana::filesystem::file_iterator i(head); i != end; ++i) for(nana::filesystem::file_iterator i(head); i != end; ++i)
@ -556,17 +557,17 @@ namespace nana
path_.childset(i->name, 0); path_.childset(i->name, 0);
} }
auto cat_path = path_.caption(); auto cat_path = path_.caption();
if(cat_path.size() && cat_path[cat_path.size() - 1] != STR('/')) if(cat_path.size() && cat_path[cat_path.size() - 1] != '/')
cat_path += STR('/'); cat_path += '/';
auto beg = head.size(); auto beg = head.size();
while(true) while(true)
{ {
auto pos = path.find(STR('/'), beg); auto pos = path.find('/', beg);
auto folder = path.substr(beg, pos != path.npos ? pos - beg: path.npos); auto folder = path.substr(beg, pos != path.npos ? pos - beg: path.npos);
if(folder.size() == 0) break; if(folder.size() == 0) break;
(cat_path += folder) += STR('/'); (cat_path += folder) += '/';
(head += folder) += STR('/'); (head += folder) += '/';
path_.caption(cat_path); path_.caption(cat_path);
for(nana::filesystem::file_iterator i(head); i != end; ++i) for(nana::filesystem::file_iterator i(head); i != end; ++i)
@ -583,7 +584,7 @@ namespace nana
_m_list_fs(); _m_list_fs();
} }
bool _m_filter_allowed(const nana::string& name, bool is_dir, const nana::string& filter, const std::vector<nana::string>* extension) const bool _m_filter_allowed(const std::string& name, bool is_dir, const std::string& filter, const std::vector<std::string>* extension) const
{ {
if(filter.size() && (name.find(filter) == filter.npos)) if(filter.size() && (name.find(filter) == filter.npos))
return false; return false;
@ -601,12 +602,12 @@ namespace nana
void _m_list_fs() void _m_list_fs()
{ {
nana::string filter = filter_.caption(); auto filter = filter_.caption();
ls_file_.auto_draw(false); ls_file_.auto_draw(false);
ls_file_.clear(); ls_file_.clear();
std::vector<nana::string>* ext_types = cb_types_.anyobj<std::vector<nana::string> >(cb_types_.option()); auto ext_types = cb_types_.anyobj<std::vector<std::string> >(cb_types_.option());
auto cat = ls_file_.at(0); auto cat = ls_file_.at(0);
for(auto & fs: file_container_) for(auto & fs: file_container_)
{ {
@ -618,7 +619,7 @@ namespace nana
ls_file_.auto_draw(true); ls_file_.auto_draw(true);
} }
void _m_finish(kind::t type, const nana::string& tar) void _m_finish(kind::t type, const std::string& tar)
{ {
selection_.target = tar; selection_.target = tar;
selection_.type = type; selection_.type = type;
@ -635,11 +636,11 @@ namespace nana
{ {
auto path = tx_path_.caption(); auto path = tx_path_.caption();
msgbox mb(fm_, STR("Create Folder")); msgbox mb(fm_, "Create Folder");
mb.icon(msgbox::icon_warning); mb.icon(msgbox::icon_warning);
if(0 == path.size() || path[0] == STR('.') || path[0] == STR('/')) if(0 == path.size() || path[0] == '.' || path[0] == '/')
{ {
mb<<STR("Please input a valid name for the new folder."); mb<<L"Please input a valid name for the new folder.";
mb(); mb();
return; return;
} }
@ -648,9 +649,9 @@ namespace nana
if(false == nana::filesystem::mkdir(fb_.addr_.filesystem + path, if_exist)) if(false == nana::filesystem::mkdir(fb_.addr_.filesystem + path, if_exist))
{ {
if(if_exist) if(if_exist)
mb<<STR("The folder is existing, please rename it."); mb<<L"The folder is existing, please rename it.";
else else
mb<<STR("Failed to create the folder, please rename it."); mb<<L"Failed to create the folder, please rename it.";
mb(); mb();
return; return;
} }
@ -663,29 +664,29 @@ namespace nana
textbox & tx_path_; textbox & tx_path_;
}; };
bool _m_append_def_extension(nana::string& tar) const bool _m_append_def_extension(std::string& tar) const
{ {
auto dotpos = tar.find_last_of(STR('.')); auto dotpos = tar.find_last_of('.');
if(dotpos != tar.npos) if(dotpos != tar.npos)
{ {
auto pos = tar.find_last_of(STR("/\\")); auto pos = tar.find_last_of("/\\");
if(pos == tar.npos || pos < dotpos) if(pos == tar.npos || pos < dotpos)
return false; return false;
} }
if(def_ext_.size()) if(def_ext_.size())
{ {
if(def_ext_[0] != STR('.')) if(def_ext_[0] != '.')
tar += STR('.'); tar += '.';
tar += def_ext_; tar += def_ext_;
} }
std::vector<nana::string> * exts = cb_types_.anyobj<std::vector<nana::string> >(cb_types_.option()); auto exts = cb_types_.anyobj<std::vector<std::string> >(cb_types_.option());
if(0 == exts || exts->size() == 0) return false; if(0 == exts || exts->size() == 0) return false;
auto & ext = exts->at(0); auto & ext = exts->at(0);
if(def_ext_[0] != STR('.')) if(def_ext_[0] != '.')
tar += STR('.'); tar += '.';
tar += ext; tar += ext;
return true; return true;
} }
@ -703,7 +704,7 @@ namespace nana
if(event_code::dbl_click == arg.evt_code) if(event_code::dbl_click == arg.evt_code)
{ {
if(m.directory) if(m.directory)
_m_load_cat_path(addr_.filesystem + m.name + STR("/")); _m_load_cat_path(addr_.filesystem + m.name + "/");
else else
_m_finish(kind::filesystem, addr_.filesystem + m.name); _m_finish(kind::filesystem, addr_.filesystem + m.name);
} }
@ -724,16 +725,16 @@ namespace nana
auto file = tb_file_.caption(); auto file = tb_file_.caption();
if(file.size()) if(file.size())
{ {
if(file[0] == STR('.')) if(file[0] == L'.')
{ {
msgbox mb(*this, caption()); msgbox mb(*this, caption());
mb.icon(msgbox::icon_warning); mb.icon(msgbox::icon_warning);
mb<<file<<std::endl<<STR("The filename is invalid."); mb<<file<<std::endl<<L"The filename is invalid.";
mb(); mb();
return; return;
} }
nana::string tar; std::string tar;
if(file[0] == STR('/')) if(file[0] == '/')
tar = file; tar = file;
else else
tar = addr_.filesystem + file; tar = addr_.filesystem + file;
@ -751,7 +752,7 @@ namespace nana
if(good && attr.is_directory) if(good && attr.is_directory)
{ {
_m_load_cat_path(tar); _m_load_cat_path(tar);
tb_file_.caption(STR("")); tb_file_.caption("");
return; return;
} }
@ -761,7 +762,7 @@ namespace nana
{ {
msgbox mb(*this, caption()); msgbox mb(*this, caption());
mb.icon(msgbox::icon_information); mb.icon(msgbox::icon_information);
mb<<STR("The file \"")<<tar<<STR("\"\n is not existing. Please check and retry."); mb<<L"The file \""<<nana::charset(tar, nana::unicode::utf8)<<L"\"\n is not existing. Please check and retry.";
mb(); mb();
} }
else else
@ -773,7 +774,7 @@ namespace nana
{ {
msgbox mb(*this, caption(), msgbox::yes_no); msgbox mb(*this, caption(), msgbox::yes_no);
mb.icon(msgbox::icon_question); mb.icon(msgbox::icon_question);
mb<<STR("The input file is existing, do you want to overwrite it?"); mb<<L"The input file is existing, do you want to overwrite it?";
if(msgbox::pick_no == mb()) if(msgbox::pick_no == mb())
return; return;
} }
@ -791,7 +792,7 @@ namespace nana
if(kind::filesystem == node.value<kind::t>()) if(kind::filesystem == node.value<kind::t>())
{ {
nana::string path = tree_.make_key_path(node, STR("/")) + STR("/"); auto path = tree_.make_key_path(node, "/") + "/";
_m_resolute_path(path); _m_resolute_path(path);
nana::filesystem::file_iterator end; nana::filesystem::file_iterator end;
@ -814,7 +815,7 @@ namespace nana
} }
private: private:
bool io_read_; bool io_read_;
nana::string def_ext_; std::string def_ext_;
place place_; place place_;
categorize<int> path_; categorize<int> path_;
@ -835,22 +836,22 @@ namespace nana
}nodes_; }nodes_;
std::vector<item_fs> file_container_; std::vector<item_fs> file_container_;
struct path_tag struct path_rep
{ {
nana::string filesystem; std::string filesystem;
}addr_; }addr_;
struct selection_tag struct selection_rep
{ {
kind::t type; kind::t type;
nana::string target; std::string target;
}selection_; }selection_;
static nana::string saved_init_path; static std::string saved_init_path;
static nana::string saved_selected_path; static std::string saved_selected_path;
};//end class filebox_implement };//end class filebox_implement
nana::string filebox_implement::saved_init_path; std::string filebox_implement::saved_init_path;
nana::string filebox_implement::saved_selected_path; std::string filebox_implement::saved_selected_path;
#endif #endif
//class filebox //class filebox
@ -1040,11 +1041,11 @@ namespace nana
{ {
for(auto & f: impl_->filters) for(auto & f: impl_->filters)
{ {
nana::string fs = f.type; std::string fs = f.type;
std::size_t pos = 0; std::size_t pos = 0;
while(true) while(true)
{ {
pos = fs.find(STR(" "), pos); pos = fs.find(" ", pos);
if(pos == fs.npos) if(pos == fs.npos)
break; break;
fs.erase(pos); fs.erase(pos);
@ -1053,7 +1054,7 @@ namespace nana
} }
} }
else else
fb.add_filter(STR("All Files"), STR("*.*")); fb.add_filter("All Files", "*.*");
fb.load_fs(impl_->path, impl_->file); fb.load_fs(impl_->path, impl_->file);

View File

@ -38,7 +38,7 @@ namespace nana
: public form : public form
{ {
public: public:
msgbox_window(window wd, const ::nana::string& title, msgbox::button_t btn, msgbox::icon_t ico) msgbox_window(window wd, const std::string& title, msgbox::button_t btn, msgbox::icon_t ico)
: form(wd, rectangle(1, 1, 1, 1), appear::decorate<>()), : form(wd, rectangle(1, 1, 1, 1), appear::decorate<>()),
owner_(wd), pick_(msgbox::pick_yes) owner_(wd), pick_(msgbox::pick_yes)
{ {
@ -61,14 +61,14 @@ namespace nana
{ {
_m_click(arg); _m_click(arg);
}); });
yes_.caption(STR("OK")); yes_.caption("OK");
width_pixel += 77; width_pixel += 77;
if(msgbox::yes_no == btn || msgbox::yes_no_cancel == btn) if(msgbox::yes_no == btn || msgbox::yes_no_cancel == btn)
{ {
yes_.caption(STR("Yes")); yes_.caption("Yes");
no_.create(*this); no_.create(*this);
no_.caption(STR("No")); no_.caption("No");
no_.events().click.connect_unignorable([this](const arg_click& arg) no_.events().click.connect_unignorable([this](const arg_click& arg)
{ {
_m_click(arg); _m_click(arg);
@ -79,7 +79,7 @@ namespace nana
if(msgbox::yes_no_cancel == btn) if(msgbox::yes_no_cancel == btn)
{ {
cancel_.create(*this); cancel_.create(*this);
cancel_.caption(STR("Cancel")); cancel_.caption("Cancel");
cancel_.events().click.connect_unignorable([this](const arg_click& arg) cancel_.events().click.connect_unignorable([this](const arg_click& arg)
{ {
_m_click(arg); _m_click(arg);
@ -843,7 +843,7 @@ namespace nana
void inputbox::text::tip_string(std::wstring tip) void inputbox::text::tip_string(std::wstring tip)
{ {
impl_->tip.swap(utf8_cast(tip)); impl_->tip = utf8_cast(tip);
} }
void inputbox::text::tip_string(std::string tip_utf8) void inputbox::text::tip_string(std::string tip_utf8)

View File

@ -400,14 +400,12 @@ namespace nana{ namespace drawerbase
button::button(window wd, const std::string& text, bool visible) button::button(window wd, const std::string& text, bool visible)
{ {
throw_not_utf8(text);
create(wd, rectangle(), visible); create(wd, rectangle(), visible);
caption(text); caption(text);
} }
button::button(window wd, const char* text, bool visible) button::button(window wd, const char* text, bool visible)
{ {
throw_not_utf8(text, std::strlen(text));
create(wd, rectangle(), visible); create(wd, rectangle(), visible);
caption(text); caption(text);
} }

View File

@ -997,7 +997,7 @@ namespace nana
auto editor = _m_impl().editor(); auto editor = _m_impl().editor();
if (editor) if (editor)
editor->text(to_nstring(str)); editor->text(to_wstring(str));
API::refresh_window(*this); API::refresh_window(*this);
} }

View File

@ -166,7 +166,7 @@ namespace nana
oresolver& oresolver::operator<<(const wchar_t* text) oresolver& oresolver::operator<<(const wchar_t* text)
{ {
cells_.emplace_back(utf8_cast(text)); cells_.emplace_back(to_utf8(text));
return *this; return *this;
} }
@ -178,13 +178,13 @@ namespace nana
oresolver& oresolver::operator<<(const std::wstring& text) oresolver& oresolver::operator<<(const std::wstring& text)
{ {
cells_.emplace_back(utf8_cast(text)); cells_.emplace_back(to_utf8(text));
return *this; return *this;
} }
oresolver& oresolver::operator<<(std::wstring&& text) oresolver& oresolver::operator<<(std::wstring&& text)
{ {
cells_.emplace_back(utf8_cast(text)); cells_.emplace_back(to_utf8(text));
return *this; return *this;
} }
@ -298,7 +298,7 @@ namespace nana
iresolver& iresolver::operator>>(std::wstring& text) iresolver& iresolver::operator>>(std::wstring& text)
{ {
if (pos_ < cells_.size()) if (pos_ < cells_.size())
text = utf8_cast(cells_[pos_++].text); text = to_wstring(cells_[pos_++].text);
return *this; return *this;
} }
@ -353,21 +353,20 @@ namespace nana
return idx; return idx;
} }
std::string to_string(const export_options& exp_opt) const std::string to_string(const export_options& exp_opt) const
{ {
std::string head_str; std::string head_str;
bool first{true}; bool first{true};
for( size_type idx{}; idx<exp_opt.columns_order.size(); ++idx) for( size_type idx{}; idx<exp_opt.columns_order.size(); ++idx)
{ {
if(first) if(first)
first=false; first=false;
else else
head_str += exp_opt.sep; head_str += exp_opt.sep;
head_str += to_utf8(column_ref(exp_opt.columns_order[idx]).text);
head_str += utf8_cast(column_ref(exp_opt.columns_order[idx]).text);
} }
return head_str; return head_str;
} }
bool visible() const bool visible() const
{ {
@ -2599,7 +2598,7 @@ namespace nana
if(first) if(first)
first=false; first=false;
else else
list_str += (utf8_cast(cat.text) + exp_opt.endl); list_str += (to_utf8(cat.text) + exp_opt.endl);
for (auto i : cat.sorted) for (auto i : cat.sorted)
{ {
@ -2979,7 +2978,7 @@ namespace nana
graph->string({ x + 20, y + txtoff }, categ.text, txt_color); graph->string({ x + 20, y + txtoff }, categ.text, txt_color);
native_string_type str = L'(' + to_nstring(categ.items.size()) + L')'; native_string_type str = to_nstring('(' + std::to_string(categ.items.size()) + ')');
auto text_s = graph->text_extent_size(categ.text).width; auto text_s = graph->text_extent_size(categ.text).width;
auto extend_text_w = text_s + graph->text_extent_size(str).width; auto extend_text_w = text_s + graph->text_extent_size(str).width;
@ -3822,7 +3821,7 @@ namespace nana
item_proxy& item_proxy::text(size_type col, std::wstring str) item_proxy& item_proxy::text(size_type col, std::wstring str)
{ {
ess_->lister.text(cat_, pos_.item, col, utf8_cast(str), columns()); ess_->lister.text(cat_, pos_.item, col, to_utf8(str), columns());
ess_->update(); ess_->update();
return *this; return *this;
} }
@ -3864,7 +3863,7 @@ namespace nana
bool item_proxy::operator==(const std::wstring& s) const bool item_proxy::operator==(const std::wstring& s) const
{ {
return (ess_->lister.get_cells(cat_, pos_.item).at(0).text == utf8_cast(s)); return (ess_->lister.get_cells(cat_, pos_.item).at(0).text == to_utf8(s));
} }
item_proxy & item_proxy::operator=(const item_proxy& rhs) item_proxy & item_proxy::operator=(const item_proxy& rhs)
@ -4007,7 +4006,7 @@ namespace nana
size_type pos = 0; size_type pos = 0;
for (auto & txt : arg) for (auto & txt : arg)
{ {
ip.text(pos++, utf8_cast(txt)); ip.text(pos++, to_utf8(txt));
if (pos >= items) if (pos >= items)
break; break;
} }
@ -4062,7 +4061,7 @@ namespace nana
std::string cat_proxy::text() const std::string cat_proxy::text() const
{ {
internal_scope_guard lock; internal_scope_guard lock;
return utf8_cast(cat_->text); return to_utf8(cat_->text);
} }
void cat_proxy::push_back(std::string s) void cat_proxy::push_back(std::string s)
@ -4479,7 +4478,7 @@ namespace nana
void listbox::insert(const index_pair& pos, std::wstring text) void listbox::insert(const index_pair& pos, std::wstring text)
{ {
insert(pos, utf8_cast(text)); insert(pos, to_utf8(text));
} }
void listbox::checkable(bool chkable) void listbox::checkable(bool chkable)

View File

@ -1179,7 +1179,7 @@ namespace nana{ namespace widgets
if ( kwptr->kwbase.empty() || text.empty() ) if ( kwptr->kwbase.empty() || text.empty() )
return; return;
using index = std::wstring::size_type; using index = std::wstring::size_type;
std::vector<entity> entities; std::vector<entity> entities;
@ -1202,7 +1202,7 @@ namespace nana{ namespace widgets
return true; return true;
}; };
::nana::cistring cistr; ::nana::ciwstring cistr;
for (auto & ds : kwptr->kwbase) for (auto & ds : kwptr->kwbase)
{ {
index pos{0} ; index pos{0} ;

View File

@ -218,7 +218,7 @@ namespace drawerbase {
textbox::textbox(window wd, const char* text, bool visible) textbox::textbox(window wd, const char* text, bool visible)
{ {
throw_not_utf8(text, std::strlen(text)); throw_not_utf8(text);
create(wd, rectangle(), visible); create(wd, rectangle(), visible);
caption(text); caption(text);
} }

View File

@ -56,7 +56,7 @@ namespace nana
std::string widget::caption() const throw() std::string widget::caption() const throw()
{ {
return utf8_cast(_m_caption()); return to_utf8(_m_caption());
} }
std::wstring widget::caption_wstring() const throw() std::wstring widget::caption_wstring() const throw()
@ -64,7 +64,7 @@ namespace nana
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
return _m_caption(); return _m_caption();
#else #else
return utf8_cast(_m_caption()); return to_wstring(_m_caption());
#endif #endif
} }

View File

@ -209,7 +209,12 @@ namespace paint
image::image_impl_interface * helper = nullptr; image::image_impl_interface * helper = nullptr;
{ {
std::transform(extension.begin(), extension.end(), extension.begin(), std::tolower); std::transform(extension.begin(), extension.end(), extension.begin(), [](int ch)
{
if('A' <= ch && ch <= 'Z')
ch -= ('A' - 'a');
return ch;
});
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
const wchar_t* ext_ico = L".ico"; const wchar_t* ext_ico = L".ico";

View File

@ -32,8 +32,8 @@ namespace nana{ namespace system{
#ifdef NANA_WINDOWS #ifdef NANA_WINDOWS
std::wstring wstr = ::nana::charset(text, nana::unicode::utf8); std::wstring wstr = ::nana::charset(text, nana::unicode::utf8);
_m_set(format::text, wstr.c_str(), (wstr.length() + 1) * sizeof(wchar_t)); _m_set(format::text, wstr.c_str(), (wstr.length() + 1) * sizeof(wchar_t));
#else #elif defined(NANA_X11)
_m_set(format::text, text, std::strlen(text) + 1); _m_set(format::text, text.c_str(), text.length() + 1);
#endif #endif
} }
@ -212,14 +212,14 @@ namespace nana{ namespace system{
if(owner) if(owner)
{ {
Atom atom_type; Atom atom_type;
switch(type) switch(fmt)
{ {
case format::text: atom_type = spec.atombase().utf8_string; break; case format::text: atom_type = spec.atombase().utf8_string; break;
default: default:
return false; return false;
} }
spec.write_selection(owner, spec.atombase().utf8_string, buf, size); spec.write_selection(owner, atom_type, buf, size);
return true; return true;
} }
#endif #endif
@ -265,7 +265,7 @@ namespace nana{ namespace system{
{ {
Atom atom; Atom atom;
switch(type) switch(fmt)
{ {
case format::text: atom = spec.atombase().utf8_string; break; case format::text: atom = spec.atombase().utf8_string; break;
default: default: