remove macro STR

This commit is contained in:
Jinhao
2015-11-29 22:38:22 +08:00
parent 12358a5dc0
commit c86a00bea5
31 changed files with 410 additions and 331 deletions

View File

@@ -154,7 +154,7 @@ namespace detail
//class platform_spec
platform_spec::co_initializer::co_initializer()
: ole32_(::LoadLibrary(STR("OLE32.DLL")))
: ole32_(::LoadLibrary(L"OLE32.DLL"))
{
if(ole32_)
{

View File

@@ -24,12 +24,12 @@ namespace filesystem
{}
#if defined(NANA_WINDOWS)
fileinfo::fileinfo(const WIN32_FIND_DATA& wfd)
: name(wfd.cFileName), size(wfd.nFileSizeLow),
: name(utf8_cast(wfd.cFileName)), size(wfd.nFileSizeLow),
directory((FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY)
{
}
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
fileinfo::fileinfo(const nana::string& name, const struct stat& fst)
fileinfo::fileinfo(const ::std::string& name, const struct stat& fst)
:name(name), size(fst.st_size), directory(0 != S_ISDIR(fst.st_mode))
{
}

View File

@@ -43,51 +43,50 @@ namespace nana {
{
//Because of No wide character version of POSIX
#if defined(NANA_LINUX) || defined(NANA_MACOS)
typedef std::string string_t;
const char* splstr = "/\\";
const char* splstr = "/";
#else
typedef nana::string string_t;
const nana::char_t* splstr = STR("/\\");
const wchar_t* splstr = L"/\\";
#endif
//class path
path::path() {}
path::path(const nana::string& text)
#if defined(NANA_WINDOWS)
: text_(text)
path::path(const value_type* source)
: path(string_type{ source })
{}
path::path(const string_type& source)
: pathstr_(source)
{
#else
:text_(nana::charset(text))
auto pos = pathstr_.find_last_of(splstr);
for (; (pos != string_type::npos) && (pos + 1 == pathstr_.size()); pos = pathstr_.find_last_of(splstr))
pathstr_.erase(pos);
}
int path::compare(const path& p) const
{
#endif
auto pos = text_.find_last_of(splstr);
for (; (pos != string_t::npos) && (pos + 1 == text_.size()); pos = text_.find_last_of(splstr))
text_.erase(pos);
return pathstr_.compare(p.pathstr_);
}
bool path::empty() const
{
#if defined(NANA_WINDOWS)
return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES);
return (::GetFileAttributes(pathstr_.c_str()) == INVALID_FILE_ATTRIBUTES);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat sta;
return (::stat(text_.c_str(), &sta) == -1);
return (::stat(pathstr_.c_str(), &sta) == -1);
#endif
}
path path::root() const
path path::parent_path() const
{
#if defined(NANA_WINDOWS)
return path(filesystem::root(text_));
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
return path(filesystem::root(nana::charset(text_)));
#endif
return{filesystem::parent_path(pathstr_)};
}
file_type path::what() const
{
#if defined(NANA_WINDOWS)
unsigned long attr = ::GetFileAttributes(text_.c_str());
unsigned long attr = ::GetFileAttributes(pathstr_.c_str());
if (INVALID_FILE_ATTRIBUTES == attr)
return file_type::not_found; //??
@@ -97,7 +96,7 @@ namespace nana {
return file_type::regular;
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat sta;
if (-1 == ::stat(text_.c_str(), &sta))
if (-1 == ::stat(pathstr_.c_str(), &sta))
return file_type::not_found; //??
if ((S_IFDIR & sta.st_mode) == S_IFDIR)
@@ -110,38 +109,85 @@ namespace nana {
#endif
}
nana::string path::filename() const
path path::filename() const
{
string_t::size_type pos = text_.find_last_of(splstr);
#if defined(NANA_WINDOWS)
return text_.substr(pos + 1);
#else
return nana::charset(text_.substr(pos + 1));
#endif
auto pos = pathstr_.find_last_of(splstr);
if (pos != pathstr_.npos)
{
if (pos + 1 == pathstr_.size())
{
value_type tmp[2] = {preferred_separator, 0};
if (pathstr_.npos != pathstr_.find_last_not_of(splstr, pos))
tmp[0] = '.';
return{ tmp };
}
return{ pathstr_.substr(pos + 1) };
}
return{ pathstr_ };
}
const path::value_type* path::c_str() const
{
return native().c_str();
}
const path::string_type& path::native() const
{
return pathstr_;
}
path::operator string_type() const
{
return native();
}
//end class path
bool operator==(const path& lhs, const path& rhs)
{
return (lhs.compare(rhs) == 0);
}
bool operator!=(const path& lhs, const path& rhs)
{
return (lhs.native() != rhs.native());
}
bool operator<(const path& lhs, const path& rhs)
{
return (lhs.compare(rhs) < 0);
}
bool operator>(const path& lhs, const path& rhs)
{
return (rhs.compare(lhs) < 0);
}
namespace detail
{
//rm_dir_recursive
//@brief: remove a directory, if it is not empty, recursively remove it's subfiles and sub directories
bool rm_dir_recursive(nana::string&& dir)
template<typename CharT>
bool rm_dir_recursive(const CharT* dir)
{
std::vector<directory_iterator::value_type> files;
nana::string path = dir;
std::basic_string<CharT> path = dir;
path += '\\';
std::copy(directory_iterator(dir), directory_iterator(), std::back_inserter(files));
for (auto & f : files)
{
auto subpath = path + f.path().filename().native();
if (f.attr.directory)
rm_dir_recursive(path + f.path().filename());
rm_dir_recursive(subpath.c_str());
else
rmfile((path + f.path().filename()).c_str());
rmfile(subpath.c_str());
}
return rmdir(dir.c_str(), true);
return rmdir(dir, true);
}
bool mkdir_helper(const nana::string& dir, bool & if_exist)
@@ -299,7 +345,7 @@ namespace nana {
nana::string root;
#if defined(NANA_WINDOWS)
if (path.size() > 3 && path[1] == STR(':'))
if (path.size() > 3 && path[1] == L':')
root = path.substr(0, 3);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
if (path[0] == STR('/'))
@@ -310,11 +356,11 @@ namespace nana {
while (true)
{
beg = path.find_first_not_of(STR("/\\"), beg);
beg = path.find_first_not_of(L"/\\", beg);
if (beg == path.npos)
break;
std::size_t pos = path.find_first_of(STR("/\\"), beg + 1);
std::size_t pos = path.find_first_of(L"/\\", beg + 1);
if (pos != path.npos)
{
root += path.substr(beg, pos - beg);
@@ -324,9 +370,9 @@ namespace nana {
return false;
#if defined(NANA_WINDOWS)
root += STR('\\');
root += L'\\';
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
root += STR('/');
root += L'/';
#endif
}
else
@@ -362,18 +408,18 @@ namespace nana {
#endif
}
bool rmdir(const nana::char_t* dir, bool fails_if_not_empty)
bool rmdir(const char* dir_utf8, bool fails_if_not_empty)
{
bool ret = false;
if (dir)
if (dir_utf8)
{
#if defined(NANA_WINDOWS)
ret = (::RemoveDirectory(dir) == TRUE);
auto dir = utf8_cast(dir_utf8);
ret = (::RemoveDirectory(dir.c_str()) == TRUE);
if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY))
ret = detail::rm_dir_recursive(dir);
ret = detail::rm_dir_recursive(dir.c_str());
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string mbstr = nana::charset(dir);
if (::rmdir(mbstr.c_str()))
if (::rmdir(dir_utf8))
{
if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY))
ret = detail::rm_dir_recursive(dir);
@@ -385,30 +431,26 @@ namespace nana {
return ret;
}
nana::string root(const nana::string& path)
bool rmdir(const wchar_t* dir, bool fails_if_not_empty)
{
std::size_t index = path.size();
if (index)
bool ret = false;
if (dir)
{
const nana::char_t * str = path.c_str();
for (--index; index > 0; --index)
#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()))
{
nana::char_t c = str[index];
if (c != '\\' && c != '/')
break;
}
for (--index; index > 0; --index)
{
nana::char_t c = str[index];
if (c == '\\' || c == '/')
break;
if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY))
ret = detail::rm_dir_recursive(dir);
}
else
ret = true;
#endif
}
return index ? path.substr(0, index + 1) : nana::string();
return ret;
}
nana::string path_user()

View File

@@ -13,6 +13,7 @@
#include <nana/filesystem/fs_utility.hpp>
#include <nana/filesystem/file_iterator.hpp>
#include <nana/deploy.hpp>
#include <vector>
#if defined(NANA_WINDOWS)
#include <windows.h>
@@ -47,7 +48,7 @@ namespace filesystem
const char* splstr = "/\\";
#else
typedef nana::string string_t;
const nana::char_t* splstr = STR("/\\");
const nana::char_t* splstr = L"/\\";
#endif
//class path
path::path(){}
@@ -125,10 +126,10 @@ namespace filesystem
{
//rm_dir_recursive
//@brief: remove a directory, if it is not empty, recursively remove it's subfiles and sub directories
bool rm_dir_recursive(nana::string&& dir)
bool rm_dir_recursive(std::string&& dir)
{
std::vector<file_iterator::value_type> files;
nana::string path = dir;
auto path = dir;
path += '\\';
std::copy(file_iterator(dir), file_iterator(), std::back_inserter(files));
@@ -144,10 +145,10 @@ namespace filesystem
return rmdir(dir.c_str(), true);
}
bool mkdir_helper(const nana::string& dir, bool & if_exist)
bool mkdir_helper(const std::string& dir, bool & if_exist)
{
#if defined(NANA_WINDOWS)
if(::CreateDirectory(dir.c_str(), 0))
if(::CreateDirectory(utf8_cast(dir).c_str(), 0))
{
if_exist = false;
return true;
@@ -155,7 +156,7 @@ namespace filesystem
if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(0 == ::mkdir(static_cast<std::string>(nana::charset(dir)).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
if(0 == ::mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
{
if_exist = false;
return true;
@@ -288,14 +289,14 @@ namespace filesystem
return false;
}
bool mkdir(const nana::string& path, bool & if_exist)
bool mkdir(const std::string& path, bool & if_exist)
{
if_exist = false;
if(path.size() == 0) return false;
nana::string root;
std::string root;
#if defined(NANA_WINDOWS)
if(path.size() > 3 && path[1] == STR(':'))
if(path.size() > 3 && path[1] == ':')
root = path.substr(0, 3);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(path[0] == STR('/'))
@@ -306,11 +307,11 @@ namespace filesystem
while(true)
{
beg = path.find_first_not_of(STR("/\\"), beg);
beg = path.find_first_not_of("/\\", beg);
if(beg == path.npos)
break;
std::size_t pos = path.find_first_of(STR("/\\"), beg + 1);
std::size_t pos = path.find_first_of("/\\", beg + 1);
if(pos != path.npos)
{
root += path.substr(beg, pos - beg);
@@ -320,9 +321,9 @@ namespace filesystem
return false;
#if defined(NANA_WINDOWS)
root += STR('\\');
root += L'\\';
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
root += STR('/');
root += L'/';
#endif
}
else
@@ -339,32 +340,32 @@ namespace filesystem
return mkstat;
}
bool rmfile(const nana::char_t* file)
bool rmfile(const char* file)
{
#if defined(NANA_WINDOWS)
bool ret = false;
if(file)
{
ret = (::DeleteFile(file) == TRUE);
ret = (::DeleteFile(utf8_cast(file).c_str()) == TRUE);
if(!ret)
ret = (ERROR_FILE_NOT_FOUND == ::GetLastError());
}
return ret;
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(std::remove(static_cast<std::string>(nana::charset(file)).c_str()))
if(std::remove(file))
return (errno == ENOENT);
return true;
#endif
}
bool rmdir(const nana::char_t* dir, bool fails_if_not_empty)
bool rmdir(const char* dir, bool fails_if_not_empty)
{
bool ret = false;
if(dir)
{
#if defined(NANA_WINDOWS)
ret = (::RemoveDirectory(dir) == TRUE);
ret = (::RemoveDirectory(utf8_cast(dir).c_str()) == TRUE);
if(!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY))
ret = detail::rm_dir_recursive(dir);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)

View File

@@ -202,7 +202,7 @@ namespace nana{
if(owner && (nested == false))
::ClientToScreen(reinterpret_cast<HWND>(owner), &pt);
HWND native_wd = ::CreateWindowEx(style_ex, STR("NanaWindowInternal"), STR("Nana Window"),
HWND native_wd = ::CreateWindowEx(style_ex, L"NanaWindowInternal", L"Nana Window",
style,
pt.x, pt.y, 100, 100,
reinterpret_cast<HWND>(owner), 0, ::GetModuleHandle(0), 0);
@@ -377,8 +377,8 @@ namespace nana{
if(nullptr == parent) return nullptr;
#if defined(NANA_WINDOWS)
HWND handle = ::CreateWindowEx(WS_EX_CONTROLPARENT, // Extended possibilites for variation
STR("NanaWindowInternal"),
STR("Nana Child Window"), // Title Text
L"NanaWindowInternal",
L"Nana Child Window", // Title Text
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
r.x, r.y, r.width, r.height,
reinterpret_cast<HWND>(parent), // The window is a child-window to desktop

View File

@@ -214,7 +214,7 @@ namespace detail
WNDCLASSEX wincl;
wincl.hInstance = ::GetModuleHandle(0);
wincl.lpszClassName = STR("NanaWindowInternal");
wincl.lpszClassName = L"NanaWindowInternal";
wincl.lpfnWndProc = &Bedrock_WIN32_WindowProc;
wincl.style = CS_DBLCLKS | CS_OWNDC;
wincl.cbSize = sizeof(wincl);
@@ -1175,7 +1175,7 @@ namespace detail
{
arg_dropfiles dropfiles;
std::unique_ptr<nana::char_t[]> varbuf;
std::unique_ptr<wchar_t[]> varbuf;
std::size_t bufsize = 0;
unsigned size = ::DragQueryFile(drop, 0xFFFFFFFF, 0, 0);
@@ -1189,7 +1189,8 @@ namespace detail
}
::DragQueryFile(drop, i, varbuf.get(), reqlen);
dropfiles.files.emplace_back(varbuf.get());
dropfiles.files.emplace_back(utf8_cast(varbuf.get()));
}
while(msgwnd && (msgwnd->flags.dropable == false))

View File

@@ -105,7 +105,7 @@ namespace nana
arrow.draw(graph, {}, style_.fgcolor, arrow_r, element_state::normal);
}
void item(graph_reference graph, const nana::rectangle& r, std::size_t index, const nana::string& name, unsigned txtheight, bool has_child, mouse_action state)
void item(graph_reference graph, const nana::rectangle& r, std::size_t index, const std::string& name_utf8, unsigned txtheight, bool has_child, mouse_action state)
{
nana::point strpos(r.x + 5, r.y + static_cast<int>(r.height - txtheight) / 2);
@@ -141,7 +141,7 @@ namespace nana
_m_item_bground(graph, r.x + 1, top, width, height, state_name);
graph.rectangle(r, false, clr);
}
graph.string(strpos, name, style_.fgcolor);
graph.string(strpos, name_utf8, style_.fgcolor);
if(has_child)
{
@@ -218,7 +218,7 @@ namespace nana
using node_handle = container::node_type*;
tree_wrapper()
:splitstr_(STR("\\")), cur_(nullptr)
: splitstr_("\\")
{}
bool seq(std::size_t index, std::vector<node_handle> & seqv) const
@@ -234,23 +234,23 @@ namespace nana
return false;
}
void splitstr(const nana::string& ss)
void splitstr(const std::string& ss)
{
if(ss.size())
splitstr_ = ss;
}
const nana::string& splitstr() const
const std::string& splitstr() const
{
return splitstr_;
}
nana::string path() const
std::string path() const
{
std::vector<node_handle> v;
_m_read_node_path(v);
nana::string str;
std::string str;
bool not_head = false;
for(auto i : v)
{
@@ -263,7 +263,7 @@ namespace nana
return str;
}
void path(const nana::string& key)
void path(const std::string& key)
{
cur_ = tree_.ref(key);
}
@@ -292,7 +292,7 @@ namespace nana
cur_ = i;
}
void insert(const nana::string& name, const nana::any& value)
void insert(const std::string& name, const nana::any& value)
{
item_tag m;
m.pixels = 0;
@@ -300,7 +300,7 @@ namespace nana
cur_ = tree_.insert(cur_, name, m);
}
bool childset(const nana::string& name, const nana::any& value)
bool childset(const std::string& name, const nana::any& value)
{
if(cur_)
{
@@ -313,7 +313,7 @@ namespace nana
return false;
}
bool childset_erase(const nana::string& name)
bool childset_erase(const std::string& name)
{
if(cur_)
{
@@ -329,7 +329,7 @@ namespace nana
return false;
}
node_handle find_child(const nana::string& name) const
node_handle find_child(const std::string& name) const
{
if(cur_)
{
@@ -360,8 +360,8 @@ namespace nana
}
private:
container tree_;
nana::string splitstr_;
node_handle cur_;
std::string splitstr_ ;
node_handle cur_{ nullptr };
};
//class scheme
@@ -543,7 +543,7 @@ namespace nana
{
if(node)
{
API::dev::window_caption(window_handle(), utf8_cast(tree().path()));
API::dev::window_caption(window_handle(), tree().path());
if(evt_holder_.selected)
evt_holder_.selected(node->value.second.value);
}
@@ -565,7 +565,7 @@ namespace nana
if(i)
{
for(node_handle child = i->child; child; child = child->next)
style_.module.items.emplace_back(std::make_shared<item>(utf8_cast(child->value.first)));
style_.module.items.emplace_back(std::make_shared<item>(child->value.first));
}
r = style_.active_item_rectangle;
}
@@ -576,7 +576,7 @@ namespace nana
{
auto end = v.cbegin() + head_;
for(auto i = v.cbegin(); i != end; ++i)
style_.module.items.emplace_back(std::make_shared<item>(utf8_cast((*i)->value.first)));
style_.module.items.emplace_back(std::make_shared<item>((*i)->value.first));
}
r = style_.active_item_rectangle;
}
@@ -603,8 +603,7 @@ namespace nana
case ui_element::item_arrow:
{
treebase_.tail(style_.active);
nana::string name = utf8_cast(style_.module.items[style_.module.index]->text());
node_handle node = treebase_.find_child(name);
node_handle node = treebase_.find_child(style_.module.items[style_.module.index]->text());
if(node)
{
treebase_.cur(node);
@@ -769,7 +768,6 @@ namespace nana
private:
window window_{nullptr};
nana::paint::graphics * graph_{nullptr};
nana::string splitstr_;
std::size_t head_;
unsigned item_height_;
std::size_t item_lines_;
@@ -808,14 +806,14 @@ namespace nana
void trigger::insert(const std::string& str, nana::any value)
{
throw_not_utf8(str);
scheme_->tree().insert(utf8_cast(str), value);
API::dev::window_caption(scheme_->window_handle(), utf8_cast(scheme_->tree().path()));
scheme_->tree().insert(str, value);
API::dev::window_caption(scheme_->window_handle(), scheme_->tree().path());
scheme_->draw();
}
bool trigger::childset(const std::string& str, nana::any value)
{
if(scheme_->tree().childset(utf8_cast(str), value))
if(scheme_->tree().childset(str, value))
{
scheme_->draw();
return true;
@@ -825,7 +823,7 @@ namespace nana
bool trigger::childset_erase(const std::string& str)
{
if(scheme_->tree().childset_erase(utf8_cast(str)))
if(scheme_->tree().childset_erase(str))
{
scheme_->draw();
return true;
@@ -843,24 +841,24 @@ namespace nana
return false;
}
void trigger::splitstr(const nana::string& sstr)
void trigger::splitstr(const std::string& sstr)
{
scheme_->tree().splitstr(sstr);
}
const nana::string& trigger::splitstr() const
const std::string& trigger::splitstr() const
{
return scheme_->tree().splitstr();
}
void trigger::path(const std::string& str)
{
scheme_->tree().path(utf8_cast(str));
scheme_->tree().path(str);
}
std::string trigger::path() const
{
return utf8_cast(scheme_->tree().path());
return scheme_->tree().path();
}
nana::any& trigger::value() const

View File

@@ -49,7 +49,7 @@ namespace checkbox
{
_m_draw_background(graph);
_m_draw_title(graph);
_m_draw_checkbox(graph, graph.text_extent_size(STR("jN"), 2).height + 2);
_m_draw_checkbox(graph, graph.text_extent_size(L"jN", 2).height + 2);
}
void drawer::mouse_down(graph_reference graph, const arg_mouse&)

View File

@@ -109,7 +109,7 @@ namespace nana
unsigned item_pixels(graph_reference graph) const
{
return graph.text_extent_size(STR("jHWn/?\\{[(0569")).height + 4;
return graph.text_extent_size(L"jHWn/?\\{[(0569").height + 4;
}
};//end class item_renderer
@@ -325,7 +325,7 @@ namespace nana
_m_open_scrollbar(*widget_, pages);
}
else
graph_->string({ 4, 4 }, STR("Empty Listbox, No Module!"), static_cast<color_rgb>(0x808080));
graph_->string({ 4, 4 }, L"Empty Listbox, No Module!", static_cast<color_rgb>(0x808080));
//Draw border
graph_->rectangle(false, colors::black);

View File

@@ -82,7 +82,7 @@ namespace nana
nana::paint::font ft = graph.typeface(); //used for restoring the font
const unsigned def_line_pixels = graph.text_extent_size(STR(" "), 1).height;
const unsigned def_line_pixels = graph.text_extent_size(L" ", 1).height;
font_ = ft;
fblock_ = nullptr;
@@ -169,7 +169,7 @@ namespace nana
auto ft = graph.typeface(); //used for restoring the font
const unsigned def_line_pixels = graph.text_extent_size(STR(" "), 1).height;
const unsigned def_line_pixels = graph.text_extent_size(L" ", 1).height;
font_ = ft;
fblock_ = nullptr;

View File

@@ -3146,7 +3146,7 @@ namespace nana
graph->set_color(it_bgcolor); // litter rect with the item bg end ...
graph->rectangle(rectangle{ xpos, y + 2, essence_->suspension_width, essence_->item_size - 4 }, true);
graph->string(point{ xpos, y + 2 }, STR("..."));
graph->string(point{ xpos, y + 2 }, L"...");
//Erase the part that over the next subitem.
if (display_order + 1 < seqs.size()) // this is not the last column
@@ -3284,9 +3284,9 @@ namespace nana
void trigger::typeface_changed(graph_reference graph)
{
essence_->text_height = graph.text_extent_size(STR("jHWn0123456789/<?'{[|\\_")).height;
essence_->text_height = graph.text_extent_size(L"jHWn0123456789/<?'{[|\\_").height;
essence_->item_size = essence_->text_height + 6;
essence_->suspension_width = graph.text_extent_size(STR("...")).width;
essence_->suspension_width = graph.text_extent_size(L"...").width;
}
void trigger::refresh(graph_reference)
@@ -3581,7 +3581,7 @@ namespace nana
case keyboard::os_arrow_down:
essence_->lister.move_select(up, !arg.shift, true);
break;
case STR(' ') :
case L' ':
{
selection s;
bool ck = ! essence_->lister.item_selected_all_checked(s);

View File

@@ -363,7 +363,7 @@ namespace nana
unsigned strpixels = item_r.width - 60;
int text_top_off = (item_h_px - graph.text_extent_size(STR("jh({[")).height) / 2;
int text_top_off = (item_h_px - graph.text_extent_size(L"jh({[").height) / 2;
std::size_t pos = 0;
for (auto & m : menu_->items)

View File

@@ -442,7 +442,7 @@ namespace nana{ namespace widgets
bool adjusted_cond = true;
if (static_cast<int>(text_w) < points.offset.x)
{
auto delta_pixels = editor_._m_text_extent_size(STR(" "), 4).width;
auto delta_pixels = editor_._m_text_extent_size(L" ", 4).width;
points.offset.x = (text_w > delta_pixels ? text_w - delta_pixels : 0);
}
else if (area_w && (text_w >= points.offset.x + area_w))
@@ -1614,7 +1614,7 @@ namespace nana{ namespace widgets
unsigned text_editor::line_height() const
{
return (graph_ ? (graph_.text_extent_size(STR("jH{")).height) : 0);
return (graph_ ? (graph_.text_extent_size(L"jH{").height) : 0);
}
unsigned text_editor::screen_lines() const
@@ -1764,7 +1764,7 @@ namespace nana{ namespace widgets
str = textbase_.getline(0);
for(std::size_t i = 1; i < lines; ++i)
{
str += STR("\n\r");
str += L"\n\r";
str += textbase_.getline(i);
}
}
@@ -2756,11 +2756,11 @@ namespace nana{ namespace widgets
if(a.y != b.y)
{
text = textbase_.getline(a.y).substr(a.x);
text += STR("\r\n");
text += L"\r\n";
for(unsigned i = a.y + 1; i < b.y; ++i)
{
text += textbase_.getline(i);
text += STR("\r\n");
text += L"\r\n";
}
text += textbase_.getline(b.y).substr(0, b.x);
}
@@ -2801,7 +2801,7 @@ namespace nana{ namespace widgets
std::size_t begin = 0;
while (true)
{
auto pos = text.find_first_of(STR("\r\n"), begin);
auto pos = text.find_first_of(L"\r\n", begin);
if (text.npos == pos)
{
if (!lines.empty())
@@ -2813,7 +2813,7 @@ namespace nana{ namespace widgets
pos = eat_endl(text_str, pos);
begin = text.find_first_not_of(STR("\r\n"), pos);
begin = text.find_first_not_of(L"\r\n", pos);
//The number of new lines minus one
const auto chp_end = text_str + (begin == text.npos ? text.size() : begin);
@@ -3068,7 +3068,7 @@ namespace nana{ namespace widgets
keyword_parser parser;
parser.parse(linestr, keywords_.get());
auto whitespace_w = graph_.text_extent_size(STR(" "), 1).width;
auto whitespace_w = graph_.text_extent_size(L" ", 1).width;
const auto line_h_pixels = line_height();

View File

@@ -29,11 +29,11 @@ namespace nana
{
using node_type = trigger::node_type;
bool no_sensitive_compare(const nana::string& text, const nana::char_t *pattern, std::size_t len)
bool no_sensitive_compare(const std::string& text, const char *pattern, std::size_t len)
{
if(len <= text.length())
{
const nana::char_t * s = text.c_str();
auto s = text.c_str();
for(std::size_t i = 0; i < len; ++i)
{
if('a' <= s[i] && s[i] <= 'z')
@@ -49,7 +49,7 @@ namespace nana
return false;
}
const node_type* find_track_child_node(const node_type* node, const node_type * end, const nana::char_t* pattern, std::size_t len, bool &finish)
const node_type* find_track_child_node(const node_type* node, const node_type * end, const char* pattern, std::size_t len, bool &finish)
{
if(node->value.second.expanded)
{
@@ -217,7 +217,7 @@ namespace nana
nana::scroll<true> scroll;
std::size_t prev_first_value;
mutable std::map<nana::string, node_image_tag> image_table;
mutable std::map<std::string, node_image_tag> image_table;
tree_cont_type::node_type * first;
int indent_pixels;
@@ -241,7 +241,7 @@ namespace nana
struct track_node_tag
{
nana::string key_buf;
::std::string key_buf;
std::size_t key_time;
}track_node;
@@ -320,9 +320,9 @@ namespace nana
return false;
}
const trigger::node_type* find_track_node(nana::char_t key)
const trigger::node_type* find_track_node(wchar_t key)
{
nana::string pattern;
std::string pattern;
if('a' <= key && key <= 'z') key -= 'a' - 'A';
@@ -334,8 +334,18 @@ namespace nana
pattern = track_node.key_buf;
track_node.key_time = now;
pattern += key;
track_node.key_buf += key;
if (key <= 0x7f)
{
pattern += static_cast<char>(key);
track_node.key_buf += static_cast<char>(key);
}
else
{
wchar_t wstr[2] = { key, 0 };
pattern += utf8_cast(wstr);
track_node.key_buf += utf8_cast(wstr);
}
const node_type *begin = node_state.selected ? node_state.selected : attr.tree_cont.get_root()->child;
@@ -604,7 +614,7 @@ namespace nana
std::size_t visual_item_size() const
{
return attr.tree_cont.child_size_if(nana::string{}, pred_allow_child{});
return attr.tree_cont.child_size_if(std::string(), pred_allow_child{});
}
int visible_w_pixels() const
@@ -820,7 +830,7 @@ namespace nana
}
}
item_proxy item_proxy::append(const nana::string& key, nana::string name)
item_proxy item_proxy::append(const std::string& key, std::string name)
{
if(nullptr == trigger_ || nullptr == node_)
return item_proxy();
@@ -892,34 +902,34 @@ namespace nana
return *this;
}
const nana::string& item_proxy::icon() const
const std::string& item_proxy::icon() const
{
return node_->value.second.img_idstr;
}
item_proxy& item_proxy::icon(const nana::string& id)
item_proxy& item_proxy::icon(const std::string& id)
{
node_->value.second.img_idstr = id;
return *this;
}
item_proxy& item_proxy::key(const nana::string& kstr)
item_proxy& item_proxy::key(const std::string& kstr)
{
trigger_->rename(node_, kstr.data(), nullptr);
return *this;
}
const nana::string& item_proxy::key() const
const std::string& item_proxy::key() const
{
return node_->value.first;
}
const nana::string& item_proxy::text() const
const std::string& item_proxy::text() const
{
return node_->value.second.text;
}
item_proxy& item_proxy::text(const nana::string& id)
item_proxy& item_proxy::text(const std::string& id)
{
trigger_->rename(node_, nullptr, id.data());
return *this;
@@ -973,27 +983,19 @@ namespace nana
return end();
}
bool item_proxy::operator==(const nana::string& s) const
bool item_proxy::operator==(const std::string& s) const
{
return (node_ && (node_->value.second.text == s));
}
bool item_proxy::operator==(const char* s) const
{
#if defined(NANA_UNICODE)
return (node_ && (node_->value.second.text == nana::string(nana::charset(s))));
#else
return (node_ && s && (node_->value.second.text == s));
#endif
return (node_ && (node_->value.second.text == s));
}
bool item_proxy::operator==(const wchar_t* s) const
{
#if defined(NANA_UNICODE)
return (node_ && s && (node_->value.second.text == s));
#else
return (node_ && (node_->value.second.text == nana::string(nana::charset(s))));
#endif
return (node_ && s && (node_->value.second.text == utf8_cast(s)));
}
// Behavior of Iterator
@@ -1114,7 +1116,7 @@ namespace nana
virtual unsigned item_height(graph_reference graph) const override
{
return graph.text_extent_size(STR("jH{"), 3).height + 8;
return graph.text_extent_size(L"jH{", 3).height + 8;
}
virtual unsigned item_width(graph_reference graph, const item_attribute_t& attr) const override
@@ -1468,7 +1470,7 @@ namespace nana
:expanded(false), checked(checkstate::unchecked)
{}
trigger::treebox_node_type::treebox_node_type(nana::string text)
trigger::treebox_node_type::treebox_node_type(std::string text)
:text(std::move(text)), expanded(false), checked(checkstate::unchecked)
{}
@@ -1702,7 +1704,7 @@ namespace nana
return node->value.second.value;
}
trigger::node_type* trigger::insert(node_type* node, const nana::string& key, nana::string&& title)
trigger::node_type* trigger::insert(node_type* node, const std::string& key, std::string&& title)
{
node_type * p = impl_->attr.tree_cont.node(node, key);
if(p)
@@ -1715,7 +1717,7 @@ namespace nana
return p;
}
trigger::node_type* trigger::insert(const nana::string& path, nana::string&& title)
trigger::node_type* trigger::insert(const std::string& path, std::string&& title)
{
auto x = impl_->attr.tree_cont.insert(path, treebox_node_type(std::move(title)));
if(x && impl_->attr.auto_draw && impl_->draw(true))
@@ -1781,7 +1783,7 @@ namespace nana
}
}
void trigger::set_expand(const nana::string& path, bool exp)
void trigger::set_expand(const std::string& path, bool exp)
{
if(impl_->set_expanded(impl_->attr.tree_cont.find(path), exp))
{
@@ -1790,7 +1792,7 @@ namespace nana
}
}
node_image_tag& trigger::icon(const nana::string& id) const
node_image_tag& trigger::icon(const std::string& id) const
{
auto i = impl_->shape.image_table.find(id);
if(i != impl_->shape.image_table.end())
@@ -1801,14 +1803,14 @@ namespace nana
return impl_->shape.image_table[id];
}
void trigger::icon_erase(const nana::string& id)
void trigger::icon_erase(const std::string& id)
{
impl_->shape.image_table.erase(id);
if(0 == impl_->shape.image_table.size())
impl_->data.comp_placer->enable(component::icon, false);
}
void trigger::node_icon(node_type* node, const nana::string& id)
void trigger::node_icon(node_type* node, const std::string& id)
{
if(tree().verify(node))
{
@@ -1826,7 +1828,7 @@ namespace nana
return impl_->data.comp_placer->item_width(*impl_->data.graph, node_attr);
}
bool trigger::rename(node_type *node, const nana::char_t* key, const nana::char_t* name)
bool trigger::rename(node_type *node, const char* key, const char* name)
{
if((key || name ) && tree().verify(node))
{
@@ -2194,28 +2196,28 @@ namespace nana
return get_drawer_trigger().checkable();
}
treebox::node_image_type& treebox::icon(const nana::string& id) const
treebox::node_image_type& treebox::icon(const std::string& id) const
{
return get_drawer_trigger().icon(id);
}
void treebox::icon_erase(const nana::string& id)
void treebox::icon_erase(const std::string& id)
{
get_drawer_trigger().icon_erase(id);
}
auto treebox::find(const nana::string& keypath) -> item_proxy
auto treebox::find(const std::string& keypath) -> item_proxy
{
auto * trg = &get_drawer_trigger();
return item_proxy(trg, trg->tree().find(keypath));
}
treebox::item_proxy treebox::insert(const nana::string& path_key, nana::string title)
treebox::item_proxy treebox::insert(const std::string& path_key, std::string title)
{
return item_proxy(&get_drawer_trigger(), get_drawer_trigger().insert(path_key, std::move(title)));
}
treebox::item_proxy treebox::insert(item_proxy i, const nana::string& key, nana::string title)
treebox::item_proxy treebox::insert(item_proxy i, const std::string& key, std::string title)
{
return item_proxy(&get_drawer_trigger(), get_drawer_trigger().insert(i._m_node(), key, std::move(title)));
}
@@ -2227,22 +2229,22 @@ namespace nana
return next;
}
void treebox::erase(const nana::string& keypath)
void treebox::erase(const std::string& keypath)
{
auto i = find(keypath);
if(!i.empty())
get_drawer_trigger().remove(i._m_node());
}
nana::string treebox::make_key_path(item_proxy i, const nana::string& splitter) const
std::string treebox::make_key_path(item_proxy i, const std::string& splitter) const
{
auto & tree = get_drawer_trigger().tree();
auto pnode = i._m_node();
if(tree.verify(pnode))
{
auto root = tree.get_root();
nana::string path;
nana::string temp;
std::string path;
std::string temp;
while(pnode->owner != root)
{
temp = splitter;

View File

@@ -322,8 +322,8 @@ namespace paint
handle_ = dw;
size_ = sz;
handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, STR("\t"), 1).width;
handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, STR(" "), 1).width;
handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, L"\t", 1).width;
handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, L" ", 1).width;
}
}
@@ -348,8 +348,8 @@ namespace paint
#if defined(NANA_WINDOWS)
::SelectObject(handle_->context, reinterpret_cast<HFONT>(f.impl_->font_ptr->handle));
#endif
handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, STR("\t"), 1).width;
handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, STR(" "), 1).width;
handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, L"\t", 1).width;
handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, L" ", 1).width;
if(changed_ == false) changed_ = true;
}
}
@@ -953,10 +953,16 @@ namespace paint
}
}
void graphics::string(const point& pos, const std::string& text)
void graphics::string(const point& pos, const std::string& text_utf8)
{
throw_not_utf8(text);
string(pos, static_cast<std::wstring>(::nana::charset(text, ::nana::unicode::utf8)));
throw_not_utf8(text_utf8);
string(pos, utf8_cast(text_utf8));
}
void graphics::string(const point& pos, const std::string& text_utf8, const color& clr)
{
set_text_color(clr);
string(pos, text_utf8);
}
void graphics::string(nana::point pos, const char_t* str, std::size_t len)

View File

@@ -218,7 +218,7 @@ namespace paint
do
{
if (STR("ICO") == type_str)
if (L"ICO" == type_str)
{
#if defined(NANA_WINDOWS)
helper = new detail::image_ico(true);
@@ -228,7 +228,7 @@ namespace paint
break;
}
if (STR("PNG") == type_str)
if (L"PNG" == type_str)
{
#if defined(NANA_ENABLE_PNG)
helper = new detail::image_png;
@@ -238,7 +238,7 @@ namespace paint
break;
}
if (STR("JPG") == type_str || STR("JPEG") == type_str)
if (L"JPG" == type_str || L"JPEG" == type_str)
{
#if defined(NANA_ENABLE_JPEG)
helper = new detail::image_jpeg;

View File

@@ -124,7 +124,7 @@ namespace nana
draw_string_omitted(graphics& graph, int x, int endpos, bool omitted)
: graph(graph), x(x), endpos(endpos)
{
omitted_pixels = (omitted ? graph.text_extent_size(STR("..."), 3).width : 0);
omitted_pixels = (omitted ? graph.text_extent_size(L"...", 3).width : 0);
if (endpos - x > static_cast<int>(omitted_pixels))
this->endpos -= omitted_pixels;
else
@@ -165,7 +165,7 @@ namespace nana
r.y = top;
graph.bitblt(r, dum_graph);
if(omitted_pixels)
detail::draw_string(dw, point{ endpos, top }, STR("..."), 3);
detail::draw_string(dw, point{ endpos, top }, L"...", 3);
break;
}
}

View File

@@ -104,14 +104,14 @@ namespace system
return;
#if defined(NANA_WINDOWS)
if(::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast<HINSTANCE>(32))
if(::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast<HINSTANCE>(32))
{
//Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers,
//verb implementations) that are activated using Component Object Model (COM), COM should be initialized
//before ShellExecute is called. Some Shell extensions require the COM single-threaded apartment (STA) type.
//In that case, COM should be initialized under WinXP.
nana::detail::platform_spec::co_initializer co_init;
::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL);
::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL);
}
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#endif