change some APIs for accepting utf8
This commit is contained in:
@@ -30,36 +30,6 @@
|
||||
|
||||
namespace nana
|
||||
{
|
||||
bool is_utf8(const char* str, unsigned len)
|
||||
{
|
||||
auto ustr = reinterpret_cast<const unsigned char*>(str);
|
||||
auto end = ustr + len;
|
||||
|
||||
while (ustr < end)
|
||||
{
|
||||
const auto uv = *ustr;
|
||||
if (uv < 0x80)
|
||||
{
|
||||
++ustr;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (uv < 0xC0)
|
||||
return false;
|
||||
|
||||
if ((uv < 0xE0) && (ustr + 1 < end))
|
||||
ustr += 2;
|
||||
else if (uv < 0xF0 && (ustr + 2 <= end))
|
||||
ustr += 3;
|
||||
else if (uv < 0x1F && (ustr + 3 <= end))
|
||||
ustr += 4;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class locale_initializer
|
||||
|
||||
@@ -355,6 +355,59 @@ namespace std
|
||||
|
||||
namespace nana
|
||||
{
|
||||
bool is_utf8(const char* str, unsigned len)
|
||||
{
|
||||
auto ustr = reinterpret_cast<const unsigned char*>(str);
|
||||
auto end = ustr + len;
|
||||
|
||||
while (ustr < end)
|
||||
{
|
||||
const auto uv = *ustr;
|
||||
if (uv < 0x80)
|
||||
{
|
||||
++ustr;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (uv < 0xC0)
|
||||
return false;
|
||||
|
||||
if ((uv < 0xE0) && (ustr + 1 < end))
|
||||
ustr += 2;
|
||||
else if (uv < 0xF0 && (ustr + 2 <= end))
|
||||
ustr += 3;
|
||||
else if (uv < 0x1F && (ustr + 3 <= end))
|
||||
ustr += 4;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void throw_not_utf8(const std::string& text)
|
||||
{
|
||||
if (!is_utf8(text.c_str(), text.length()))
|
||||
throw std::invalid_argument("The text is not encoded in UTF8");
|
||||
}
|
||||
|
||||
void throw_not_utf8(const char* text, unsigned len)
|
||||
{
|
||||
if (!is_utf8(text, len))
|
||||
throw std::invalid_argument("The text is not encoded in UTF8");
|
||||
}
|
||||
|
||||
std::wstring utf8_cast(const std::string& text)
|
||||
{
|
||||
return ::nana::charset(text, ::nana::unicode::utf8);
|
||||
}
|
||||
|
||||
std::string utf8_cast(const std::wstring& text)
|
||||
{
|
||||
return ::nana::charset(text).to_bytes(::nana::unicode::utf8);
|
||||
}
|
||||
|
||||
|
||||
std::size_t strlen(const char_t* str)
|
||||
{
|
||||
#if defined(NANA_UNICODE)
|
||||
|
||||
@@ -188,11 +188,12 @@ namespace filesystem
|
||||
#endif
|
||||
}//end namespace detail
|
||||
|
||||
bool file_attrib(const nana::string& file, attribute& attr)
|
||||
bool file_attrib(const std::string& file, attribute& attr)
|
||||
{
|
||||
throw_not_utf8(file);
|
||||
#if defined(NANA_WINDOWS)
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if(::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &fad))
|
||||
if(::GetFileAttributesEx(utf8_cast(file).c_str(), GetFileExInfoStandard, &fad))
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
li.u.LowPart = fad.nFileSizeLow;
|
||||
@@ -204,7 +205,7 @@ namespace filesystem
|
||||
}
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
struct stat fst;
|
||||
if(0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &fst))
|
||||
if(0 == ::stat(file.c_str(), &fst))
|
||||
{
|
||||
attr.bytes = fst.st_size;
|
||||
attr.is_directory = (0 != (040000 & fst.st_mode));
|
||||
@@ -215,7 +216,7 @@ namespace filesystem
|
||||
return false;
|
||||
}
|
||||
|
||||
long long filesize(const nana::string& file)
|
||||
long long filesize(const std::string& file)
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
//Some compilation environment may fail to link to GetFileSizeEx
|
||||
@@ -223,7 +224,7 @@ namespace filesystem
|
||||
GetFileSizeEx_fptr_t get_file_size_ex = reinterpret_cast<GetFileSizeEx_fptr_t>(::GetProcAddress(::GetModuleHandleA("Kernel32.DLL"), "GetFileSizeEx"));
|
||||
if(get_file_size_ex)
|
||||
{
|
||||
HANDLE handle = ::CreateFile(file.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
HANDLE handle = ::CreateFile(utf8_cast(file).c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if(INVALID_HANDLE_VALUE != handle)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
@@ -235,23 +236,18 @@ namespace filesystem
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#elif defined(NANA_LINUX)
|
||||
FILE * stream = ::fopen(static_cast<std::string>(nana::charset(file)).c_str(), "rb");
|
||||
#else
|
||||
auto stream = ::fopen(file.c_str(), "rb");
|
||||
long long size = 0;
|
||||
if(stream)
|
||||
{
|
||||
#if defined(NANA_LINUX)
|
||||
fseeko64(stream, 0, SEEK_END);
|
||||
size = ftello64(stream);
|
||||
fclose(stream);
|
||||
}
|
||||
return size;
|
||||
#elif defined(NANA_MACOS)
|
||||
FILE * stream = ::fopen(static_cast<std::string>(nana::charset(file)).c_str(), "rb");
|
||||
long long size = 0;
|
||||
if (stream)
|
||||
{
|
||||
#elif defined(NANA_MACOS)
|
||||
fseeko(stream, 0, SEEK_END);
|
||||
size = ftello(stream);
|
||||
#endif
|
||||
fclose(stream);
|
||||
}
|
||||
return size;
|
||||
|
||||
@@ -1076,32 +1076,22 @@ namespace nana{
|
||||
#endif
|
||||
}
|
||||
|
||||
void native_interface::window_caption(native_window_type wd, const nana::string& title)
|
||||
void native_interface::window_caption(native_window_type wd, const std::string& title)
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
std::wstring wtext = ::nana::charset(title, ::nana::unicode::utf8);
|
||||
if(::GetCurrentThreadId() != ::GetWindowThreadProcessId(reinterpret_cast<HWND>(wd), 0))
|
||||
{
|
||||
wchar_t * wstr;
|
||||
#if defined(NANA_UNICODE)
|
||||
wstr = new wchar_t[title.length() + 1];
|
||||
wcscpy(wstr, title.c_str());
|
||||
#else
|
||||
std::wstring str = nana::charset(title);
|
||||
wstr = new wchar_t[str.length() + 1];
|
||||
wcscpy(wstr, str.c_str());
|
||||
#endif
|
||||
wchar_t * wstr = new wchar_t[wtext.length() + 1];
|
||||
std::wcscpy(wstr, wtext.c_str());
|
||||
::PostMessage(reinterpret_cast<HWND>(wd), nana::detail::messages::remote_thread_set_window_text, reinterpret_cast<WPARAM>(wstr), 0);
|
||||
}
|
||||
else
|
||||
::SetWindowText(reinterpret_cast<HWND>(wd), title.c_str());
|
||||
::SetWindowText(reinterpret_cast<HWND>(wd), wtext.c_str());
|
||||
#elif defined(NANA_X11)
|
||||
::XTextProperty name;
|
||||
#if defined(NANA_UNICODE)
|
||||
std::string mbstr = nana::charset(title);
|
||||
char* text = const_cast<char*>(mbstr.c_str());
|
||||
#else
|
||||
char* text = const_cast<char*>(title.c_str());
|
||||
#endif
|
||||
char * text = const_cast<char*>(title.c_str());
|
||||
|
||||
nana::detail::platform_scope_guard psg;
|
||||
::XStringListToTextProperty(&text, 1, &name);
|
||||
::XSetWMName(restrict::spec.open_display(), reinterpret_cast<Window>(wd), &name);
|
||||
@@ -1111,7 +1101,7 @@ namespace nana{
|
||||
#endif
|
||||
}
|
||||
|
||||
nana::string native_interface::window_caption(native_window_type wd)
|
||||
std::string native_interface::window_caption(native_window_type wd)
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
int length = ::GetWindowTextLength(reinterpret_cast<HWND>(wd));
|
||||
@@ -1126,9 +1116,8 @@ namespace nana{
|
||||
//Remove the null terminator writtien by GetWindowText
|
||||
str.resize(length);
|
||||
|
||||
return str;
|
||||
return ::nana::charset(str);
|
||||
}
|
||||
return nana::string();
|
||||
#elif defined(NANA_X11)
|
||||
nana::detail::platform_scope_guard psg;
|
||||
::XTextProperty txtpro;
|
||||
@@ -1140,14 +1129,14 @@ namespace nana{
|
||||
{
|
||||
if(size > 1)
|
||||
{
|
||||
nana::string str = nana::charset(*strlist);
|
||||
std::string text = *strlist;
|
||||
::XFreeStringList(strlist);
|
||||
return str;
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nana::string();
|
||||
#endif
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void native_interface::capture_window(native_window_type wd, bool cap)
|
||||
|
||||
@@ -440,9 +440,9 @@ namespace detail
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
(msgbox(modal_window, STR("An uncaptured std::exception during message pumping: ")).icon(msgbox::icon_information)
|
||||
<<STR("\n in form: ") << API::window_caption(modal_window)
|
||||
<<STR("\n exception : ") << e.what()
|
||||
(msgbox(modal_window, "An uncaptured std::exception during message pumping: ").icon(msgbox::icon_information)
|
||||
<<"\n in form: "<< API::window_caption(modal_window)
|
||||
<<"\n exception : "<< e.what()
|
||||
).show();
|
||||
|
||||
internal_scope_guard lock;
|
||||
@@ -458,8 +458,8 @@ namespace detail
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
(msgbox(modal_window, STR("An exception during message pumping!")).icon(msgbox::icon_information)
|
||||
<< STR("An uncaptured non-std exception during message pumping!")
|
||||
(msgbox(modal_window, "An exception during message pumping!").icon(msgbox::icon_information)
|
||||
<<"An uncaptured non-std exception during message pumping!"
|
||||
).show();
|
||||
internal_scope_guard lock;
|
||||
_m_except_handler();
|
||||
|
||||
@@ -858,16 +858,16 @@ namespace nana
|
||||
{
|
||||
struct filter
|
||||
{
|
||||
nana::string des;
|
||||
nana::string type;
|
||||
std::string des;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
window owner;
|
||||
bool open_or_save;
|
||||
|
||||
nana::string file;
|
||||
nana::string title;
|
||||
nana::string path;
|
||||
std::string file;
|
||||
std::string title;
|
||||
std::string path;
|
||||
std::vector<filter> filters;
|
||||
};
|
||||
|
||||
@@ -885,9 +885,12 @@ namespace nana
|
||||
auto len = ::GetCurrentDirectory(0, nullptr);
|
||||
if(len)
|
||||
{
|
||||
impl_->path.resize(len + 1);
|
||||
::GetCurrentDirectory(len, &(impl_->path[0]));
|
||||
impl_->path.resize(len);
|
||||
std::wstring path;
|
||||
path.resize(len + 1);
|
||||
::GetCurrentDirectory(len, &(path[0]));
|
||||
path.resize(len);
|
||||
|
||||
impl_->path = utf8_cast(path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -913,13 +916,13 @@ namespace nana
|
||||
impl_->owner = wd;
|
||||
}
|
||||
|
||||
nana::string filebox::title(nana::string s)
|
||||
std::string filebox::title(std::string s)
|
||||
{
|
||||
impl_->title.swap(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
filebox& filebox::init_path(const nana::string& ipstr)
|
||||
filebox& filebox::init_path(const std::string& ipstr)
|
||||
{
|
||||
if(ipstr.empty())
|
||||
{
|
||||
@@ -935,25 +938,25 @@ namespace nana
|
||||
return *this;
|
||||
}
|
||||
|
||||
filebox& filebox::init_file(const nana::string& ifstr)
|
||||
filebox& filebox::init_file(const std::string& ifstr)
|
||||
{
|
||||
impl_->file = ifstr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
filebox& filebox::add_filter(const nana::string& description, const nana::string& filetype)
|
||||
filebox& filebox::add_filter(const std::string& description, const std::string& filetype)
|
||||
{
|
||||
implement::filter flt = {description, filetype};
|
||||
impl_->filters.push_back(flt);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nana::string filebox::path() const
|
||||
std::string filebox::path() const
|
||||
{
|
||||
return impl_->path;
|
||||
}
|
||||
|
||||
nana::string filebox::file() const
|
||||
std::string filebox::file() const
|
||||
{
|
||||
return impl_->file;
|
||||
}
|
||||
@@ -961,36 +964,36 @@ namespace nana
|
||||
bool filebox::show() const
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
if(impl_->file.size() < 520)
|
||||
impl_->file.resize(520);
|
||||
std::wstring wfile;
|
||||
wfile.resize(520);
|
||||
|
||||
OPENFILENAME ofn;
|
||||
memset(&ofn, 0, sizeof ofn);
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = reinterpret_cast<HWND>(API::root(impl_->owner));
|
||||
ofn.lpstrFile = &(impl_->file[0]);
|
||||
ofn.nMaxFile = static_cast<DWORD>(impl_->file.size() - 1);
|
||||
ofn.lpstrFile = &(wfile[0]);
|
||||
ofn.nMaxFile = static_cast<DWORD>(wfile.size() - 1);
|
||||
|
||||
const nana::char_t * filter;
|
||||
nana::string filter_holder;
|
||||
nana::string default_extension;
|
||||
const wchar_t * filter;
|
||||
std::wstring filter_holder;
|
||||
std::wstring default_extension;
|
||||
if(impl_->filters.size())
|
||||
{
|
||||
for(auto & f : impl_->filters)
|
||||
{
|
||||
filter_holder += f.des;
|
||||
filter_holder += static_cast<nana::string::value_type>('\0');
|
||||
nana::string fs = f.type;
|
||||
filter_holder += utf8_cast(f.des);
|
||||
filter_holder += static_cast<std::wstring::value_type>('\0');
|
||||
std::wstring fs = utf8_cast(f.type);
|
||||
std::size_t pos = 0;
|
||||
while(true)
|
||||
{
|
||||
pos = fs.find(STR(" "), pos);
|
||||
pos = fs.find(L" ", pos);
|
||||
if(pos == fs.npos)
|
||||
break;
|
||||
fs.erase(pos);
|
||||
}
|
||||
filter_holder += fs;
|
||||
filter_holder += static_cast<nana::string::value_type>('\0');
|
||||
filter_holder += static_cast<std::wstring::value_type>('\0');
|
||||
|
||||
//Get the default file extentsion
|
||||
if (default_extension.empty())
|
||||
@@ -1010,14 +1013,16 @@ namespace nana
|
||||
filter = filter_holder.data();
|
||||
}
|
||||
else
|
||||
filter = STR("All Files\0*.*\0");
|
||||
filter = L"All Files\0*.*\0";
|
||||
|
||||
auto wtitle = utf8_cast(impl_->title);
|
||||
auto wpath = utf8_cast(impl_->path);
|
||||
ofn.lpstrFilter = filter;
|
||||
ofn.lpstrTitle = (impl_->title.size() ? impl_->title.c_str() : nullptr);
|
||||
ofn.lpstrTitle = (wtitle.empty() ? nullptr : wtitle.c_str());
|
||||
ofn.nFilterIndex = 0;
|
||||
ofn.lpstrFileTitle = nullptr;
|
||||
ofn.nMaxFileTitle = 0;
|
||||
ofn.lpstrInitialDir = (impl_->path.size() ? impl_->path.c_str() : nullptr);
|
||||
ofn.lpstrInitialDir = (wpath.empty() ? nullptr : wpath.c_str());
|
||||
|
||||
if (!impl_->open_or_save)
|
||||
ofn.Flags = OFN_OVERWRITEPROMPT; //Overwrite prompt if it is save mode
|
||||
@@ -1026,7 +1031,8 @@ namespace nana
|
||||
if(FALSE == (impl_->open_or_save ? ::GetOpenFileName(&ofn) : ::GetSaveFileName(&ofn)))
|
||||
return false;
|
||||
|
||||
impl_->file.resize(nana::strlen(impl_->file.data()));
|
||||
wfile.resize(std::wcslen(wfile.data()));
|
||||
impl_->file = utf8_cast(wfile);
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
filebox_implement fb(impl_->owner, impl_->open_or_save, impl_->title);
|
||||
|
||||
@@ -1055,7 +1061,7 @@ namespace nana
|
||||
if(false == fb.file(impl_->file))
|
||||
return false;
|
||||
#endif
|
||||
auto tpos = impl_->file.find_last_of(STR("\\/"));
|
||||
auto tpos = impl_->file.find_last_of("\\/");
|
||||
if(tpos != impl_->file.npos)
|
||||
impl_->path = impl_->file.substr(0, tpos);
|
||||
else
|
||||
|
||||
@@ -352,13 +352,17 @@ namespace nana
|
||||
return *this;
|
||||
}
|
||||
|
||||
msgbox::msgbox(const nana::string& title)
|
||||
msgbox::msgbox(const std::string& title)
|
||||
: wd_(nullptr), title_(title), button_(ok), icon_(icon_none)
|
||||
{}
|
||||
{
|
||||
throw_not_utf8(title_);
|
||||
}
|
||||
|
||||
msgbox::msgbox(window wd, const nana::string& title, button_t b)
|
||||
msgbox::msgbox(window wd, const std::string& title, button_t b)
|
||||
: wd_(wd), title_(title), button_(b), icon_(icon_none)
|
||||
{}
|
||||
{
|
||||
throw_not_utf8(title_);
|
||||
}
|
||||
|
||||
msgbox& msgbox::icon(icon_t ic)
|
||||
{
|
||||
@@ -439,11 +443,8 @@ namespace nana
|
||||
default: break;
|
||||
}
|
||||
|
||||
#if defined(NANA_UNICODE)
|
||||
int bt = ::MessageBoxW(reinterpret_cast<HWND>(API::root(wd_)), static_cast<std::wstring>(nana::charset(sstream_.str())).c_str(), title_.c_str(), type);
|
||||
#else
|
||||
int bt = ::MessageBoxA(reinterpret_cast<HWND>(API::root(wd_), sstream_.str().c_str(), title_.c_str(), type);
|
||||
#endif
|
||||
auto bt = ::MessageBoxW(reinterpret_cast<HWND>(API::root(wd_)), utf8_cast(sstream_.str()).c_str(), utf8_cast(title_).c_str(), type);
|
||||
|
||||
switch(bt)
|
||||
{
|
||||
case IDOK:
|
||||
@@ -473,9 +474,12 @@ namespace nana
|
||||
: public ::nana::form
|
||||
{
|
||||
public:
|
||||
inputbox_window(window owner, paint::image (&imgs)[4], ::nana::rectangle (&valid_areas)[4], const ::nana::string & desc, const ::nana::string& title, std::size_t contents, unsigned fixed_pixels, const std::vector<unsigned>& each_height)
|
||||
inputbox_window(window owner, paint::image (&imgs)[4], ::nana::rectangle (&valid_areas)[4], const ::std::string & desc, const ::std::string& title, std::size_t contents, unsigned fixed_pixels, const std::vector<unsigned>& each_height)
|
||||
: form(owner, API::make_center(owner, 500, 300), appear::decorate<>())
|
||||
{
|
||||
throw_not_utf8(desc);
|
||||
throw_not_utf8(title);
|
||||
|
||||
desc_.create(*this);
|
||||
desc_.format(true).caption(desc);
|
||||
auto desc_extent = desc_.measure(470);
|
||||
@@ -652,13 +656,13 @@ namespace nana
|
||||
int last;
|
||||
int step;
|
||||
|
||||
::nana::string label_text;
|
||||
::std::string label_text;
|
||||
::nana::panel<false> dock;
|
||||
::nana::label label;
|
||||
::nana::spinbox spinbox;
|
||||
};
|
||||
|
||||
inputbox::integer::integer(::nana::string label, int init_value, int begin, int last, int step)
|
||||
inputbox::integer::integer(::std::string label, int init_value, int begin, int last, int step)
|
||||
: impl_(new implement)
|
||||
{
|
||||
auto impl = impl_.get();
|
||||
@@ -681,7 +685,7 @@ namespace nana
|
||||
}
|
||||
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& inputbox::integer::label() const
|
||||
const ::std::string& inputbox::integer::label() const
|
||||
{
|
||||
return impl_->label_text;
|
||||
}
|
||||
@@ -730,13 +734,13 @@ namespace nana
|
||||
double last;
|
||||
double step;
|
||||
|
||||
::nana::string label_text;
|
||||
::std::string label_text;
|
||||
::nana::panel<false> dock;
|
||||
::nana::label label;
|
||||
::nana::spinbox spinbox;
|
||||
};
|
||||
|
||||
inputbox::real::real(::nana::string label, double init_value, double begin, double last, double step)
|
||||
inputbox::real::real(::std::string label, double init_value, double begin, double last, double step)
|
||||
: impl_(new implement)
|
||||
{
|
||||
auto impl = impl_.get();
|
||||
@@ -759,7 +763,7 @@ namespace nana
|
||||
}
|
||||
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& inputbox::real::label() const
|
||||
const ::std::string& inputbox::real::label() const
|
||||
{
|
||||
return impl_->label_text;
|
||||
}
|
||||
@@ -803,29 +807,33 @@ namespace nana
|
||||
//class text
|
||||
struct inputbox::text::implement
|
||||
{
|
||||
::nana::string value;
|
||||
::nana::string tip;
|
||||
::std::string value;
|
||||
::std::string tip;
|
||||
wchar_t mask_character{0};
|
||||
std::vector< ::nana::string> options;
|
||||
std::vector< ::std::string> options;
|
||||
|
||||
::nana::string label_text;
|
||||
::nana::string init_text;
|
||||
::std::string label_text;
|
||||
::std::string init_text;
|
||||
::nana::panel<false> dock;
|
||||
::nana::label label;
|
||||
::nana::combox combox;
|
||||
::nana::textbox textbox;
|
||||
};
|
||||
|
||||
inputbox::text::text(::nana::string label, ::nana::string init_text)
|
||||
inputbox::text::text(::std::string label, ::std::string init_text)
|
||||
: impl_(new implement)
|
||||
{
|
||||
impl_->label_text.swap(label);
|
||||
impl_->init_text.swap(init_text);
|
||||
}
|
||||
|
||||
inputbox::text::text(::nana::string label, std::vector<::nana::string> options)
|
||||
inputbox::text::text(::std::string label, std::vector<::std::string> options)
|
||||
: impl_(new implement)
|
||||
{
|
||||
throw_not_utf8(label);
|
||||
for (auto & text : options)
|
||||
throw_not_utf8(text);
|
||||
|
||||
impl_->options.swap(options);
|
||||
impl_->label_text.swap(label);
|
||||
}
|
||||
@@ -835,12 +843,12 @@ namespace nana
|
||||
|
||||
void inputbox::text::tip_string(std::wstring tip)
|
||||
{
|
||||
impl_->tip.swap(tip);
|
||||
impl_->tip.swap(utf8_cast(tip));
|
||||
}
|
||||
|
||||
void inputbox::text::tip_string(std::string tip_utf8)
|
||||
{
|
||||
impl_->tip = ::nana::charset(tip_utf8, ::nana::unicode::utf8);
|
||||
impl_->tip.swap(tip_utf8);
|
||||
}
|
||||
|
||||
void inputbox::text::mask_character(wchar_t ch)
|
||||
@@ -848,7 +856,7 @@ namespace nana
|
||||
impl_->mask_character = ch;
|
||||
}
|
||||
|
||||
::nana::string inputbox::text::value() const
|
||||
::std::string inputbox::text::value() const
|
||||
{
|
||||
if (!impl_->textbox.empty())
|
||||
return impl_->textbox.caption();
|
||||
@@ -859,7 +867,7 @@ namespace nana
|
||||
}
|
||||
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& inputbox::text::label() const
|
||||
const ::std::string& inputbox::text::label() const
|
||||
{
|
||||
return impl_->label_text;
|
||||
}
|
||||
@@ -929,7 +937,7 @@ namespace nana
|
||||
int month;
|
||||
int day;
|
||||
|
||||
::nana::string label_text;
|
||||
::std::string label_text;
|
||||
::nana::panel<false> dock;
|
||||
::nana::label label;
|
||||
::nana::combox wdg_month;
|
||||
@@ -937,18 +945,18 @@ namespace nana
|
||||
::nana::spinbox wdg_year;
|
||||
};
|
||||
|
||||
inputbox::date::date(::nana::string label)
|
||||
inputbox::date::date(::std::string label)
|
||||
: impl_(new implement)
|
||||
{
|
||||
impl_->label_text = std::move(label);
|
||||
impl_->label_text.swap(label);
|
||||
}
|
||||
|
||||
//Instance for impl_ because implmenet is incomplete type at the point of declaration
|
||||
inputbox::date::~date(){}
|
||||
|
||||
::nana::string inputbox::date::value() const
|
||||
::std::string inputbox::date::value() const
|
||||
{
|
||||
return std::to_wstring(impl_->month) + L'-' + std::to_wstring(impl_->day) + L", " + std::to_wstring(impl_->year);
|
||||
return std::to_string(impl_->month) + '-' + std::to_string(impl_->day) + ", " + std::to_string(impl_->year);
|
||||
}
|
||||
|
||||
int inputbox::date::year() const
|
||||
@@ -974,7 +982,7 @@ namespace nana
|
||||
}
|
||||
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& inputbox::date::label() const
|
||||
const ::std::string& inputbox::date::label() const
|
||||
{
|
||||
return impl_->label_text;
|
||||
}
|
||||
@@ -1071,19 +1079,21 @@ namespace nana
|
||||
{
|
||||
filebox fbox;
|
||||
|
||||
::nana::string value;
|
||||
::nana::string label_text;
|
||||
::std::string value;
|
||||
::std::string label_text;
|
||||
::nana::panel<false> dock;
|
||||
::nana::label label;
|
||||
::nana::textbox path_edit;
|
||||
::nana::button browse;
|
||||
|
||||
implement(const filebox& fb, ::nana::string&& labelstr)
|
||||
implement(const filebox& fb, ::std::string&& labelstr)
|
||||
: fbox(fb), label_text(std::move(labelstr))
|
||||
{}
|
||||
{
|
||||
throw_not_utf8(label_text);
|
||||
}
|
||||
};
|
||||
|
||||
inputbox::path::path(::nana::string label, const filebox& fb)
|
||||
inputbox::path::path(::std::string label, const filebox& fb)
|
||||
: impl_(new implement(fb, std::move(label)))
|
||||
{
|
||||
}
|
||||
@@ -1091,7 +1101,7 @@ namespace nana
|
||||
//Instance for impl_ because implmenet is incomplete type at the point of declaration
|
||||
inputbox::path::~path(){}
|
||||
|
||||
::nana::string inputbox::path::value() const
|
||||
::std::string inputbox::path::value() const
|
||||
{
|
||||
if (!impl_->path_edit.empty())
|
||||
return impl_->path_edit.caption();
|
||||
@@ -1100,7 +1110,7 @@ namespace nana
|
||||
}
|
||||
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& inputbox::path::label() const
|
||||
const ::std::string& inputbox::path::label() const
|
||||
{
|
||||
return impl_->label_text;
|
||||
}
|
||||
@@ -1148,7 +1158,7 @@ namespace nana
|
||||
//end class path
|
||||
|
||||
|
||||
inputbox::inputbox(window owner, ::nana::string desc, ::nana::string title)
|
||||
inputbox::inputbox(window owner, ::std::string desc, ::std::string title)
|
||||
: owner_{ owner },
|
||||
description_(std::move(desc)),
|
||||
title_(std::move(title))
|
||||
|
||||
@@ -539,12 +539,12 @@ namespace nana
|
||||
});
|
||||
}
|
||||
|
||||
field_interface& operator<<(const nana::char_t* label_text) override
|
||||
field_interface& operator<<(const char* label_text) override
|
||||
{
|
||||
return static_cast<field_interface*>(this)->operator<<(agent<label>(label_text ? label_text : L""));
|
||||
return static_cast<field_interface*>(this)->operator<<(agent<label>(label_text ? label_text : ""));
|
||||
}
|
||||
|
||||
virtual field_interface& operator<<(nana::string label_text) override
|
||||
field_interface& operator<<(std::string label_text) override
|
||||
{
|
||||
return static_cast<field_interface*>(this)->operator<<(agent<label>(label_text));
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace nana
|
||||
graph.rectangle(true);
|
||||
|
||||
//draw caption
|
||||
auto text = API::window_caption(window_handle_);
|
||||
auto text = utf8_cast(API::window_caption(window_handle_));
|
||||
text_rd_->render({ 3, 1 }, text.data(), text.size(), graph.size().width - 20, true);
|
||||
|
||||
//draw x button
|
||||
@@ -300,7 +300,7 @@ namespace nana
|
||||
if (handle)
|
||||
caption_.caption(API::window_caption(handle));
|
||||
else
|
||||
caption_.caption(::nana::string());
|
||||
caption_.caption(::std::string());
|
||||
});
|
||||
|
||||
tabbar_->move({ 0, r.bottom() - 20, r.width, 20 });
|
||||
|
||||
@@ -220,7 +220,7 @@ namespace API
|
||||
}
|
||||
}
|
||||
|
||||
nana::string window_caption(window wd) throw()
|
||||
std::string window_caption(window wd) throw()
|
||||
{
|
||||
auto const iwd = reinterpret_cast<basic_window*>(wd);
|
||||
internal_scope_guard isg;
|
||||
@@ -234,7 +234,7 @@ namespace API
|
||||
return {};
|
||||
}
|
||||
|
||||
void window_caption(window wd, nana::string title)
|
||||
void window_caption(window wd, std::string title)
|
||||
{
|
||||
auto const iwd = reinterpret_cast<basic_window*>(wd);
|
||||
internal_scope_guard lock;
|
||||
@@ -819,18 +819,19 @@ namespace API
|
||||
|
||||
void window_caption(window wd, const std::string& title_utf8)
|
||||
{
|
||||
window_caption(wd, std::wstring(::nana::charset(title_utf8, ::nana::unicode::utf8)));
|
||||
throw_not_utf8(title_utf8);
|
||||
auto const iwd = reinterpret_cast<basic_window*>(wd);
|
||||
internal_scope_guard lock;
|
||||
if (restrict::wd_manager().available(iwd))
|
||||
iwd->widget_notifier->caption(title_utf8);
|
||||
}
|
||||
|
||||
void window_caption(window wd, const nana::string& title)
|
||||
{
|
||||
auto const iwd = reinterpret_cast<basic_window*>(wd);
|
||||
internal_scope_guard lock;
|
||||
if (restrict::wd_manager().available(iwd))
|
||||
iwd->widget_notifier->caption(title);
|
||||
window_caption(wd, static_cast<std::string>(::nana::charset(title).to_bytes(::nana::unicode::utf8)));
|
||||
}
|
||||
|
||||
nana::string window_caption(window wd)
|
||||
std::string window_caption(window wd)
|
||||
{
|
||||
auto const iwd = reinterpret_cast<basic_window*>(wd);
|
||||
internal_scope_guard lock;
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace nana
|
||||
return this->empty();
|
||||
}
|
||||
|
||||
void tooltip_text(const nana::string& text) override
|
||||
void tooltip_text(const std::string& text) override
|
||||
{
|
||||
label_.caption(text);
|
||||
auto text_s = label_.measure(screen().from_window(label_).workarea().width * 2 / 3);
|
||||
@@ -157,7 +157,7 @@ namespace nana
|
||||
|
||||
class controller
|
||||
{
|
||||
typedef std::pair<window, nana::string> pair_t;
|
||||
typedef std::pair<window, std::string> pair_t;
|
||||
|
||||
typedef std::function<void(tooltip_interface*)> deleter_type;
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace nana
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void set(window wd, const nana::string& str)
|
||||
void set(window wd, const std::string& str)
|
||||
{
|
||||
if (str.empty())
|
||||
_m_untip(wd);
|
||||
@@ -210,7 +210,7 @@ namespace nana
|
||||
_m_get(wd).second = str;
|
||||
}
|
||||
|
||||
void show(const nana::string& text)
|
||||
void show(const std::string& text)
|
||||
{
|
||||
if (nullptr == window_ || window_->tooltip_empty())
|
||||
{
|
||||
@@ -227,7 +227,7 @@ namespace nana
|
||||
window_->tooltip_move(API::cursor_position(), true);
|
||||
}
|
||||
|
||||
void show_duration(window wd, point pos, const nana::string& text, std::size_t duration)
|
||||
void show_duration(window wd, point pos, const std::string& text, std::size_t duration)
|
||||
{
|
||||
if (nullptr == window_ || window_->tooltip_empty())
|
||||
{
|
||||
@@ -298,7 +298,7 @@ namespace nana
|
||||
_m_untip(arg.window_handle);
|
||||
});
|
||||
|
||||
cont_.emplace_back(wd, nana::string());
|
||||
cont_.emplace_back(wd, std::string());
|
||||
return cont_.back();
|
||||
}
|
||||
private:
|
||||
@@ -311,7 +311,7 @@ namespace nana
|
||||
//class tooltip
|
||||
typedef drawerbase::tooltip::controller ctrl;
|
||||
|
||||
void tooltip::set(window wd, const nana::string& text)
|
||||
void tooltip::set(window wd, const std::string& text)
|
||||
{
|
||||
if(false == API::empty_window(wd))
|
||||
{
|
||||
@@ -320,7 +320,7 @@ namespace nana
|
||||
}
|
||||
}
|
||||
|
||||
void tooltip::show(window wd, point pos, const nana::string& text, std::size_t duration)
|
||||
void tooltip::show(window wd, point pos, const std::string& text, std::size_t duration)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
API::calc_screen_point(wd, pos);
|
||||
|
||||
@@ -212,11 +212,11 @@ namespace nana{ namespace drawerbase
|
||||
|
||||
void trigger::_m_draw_title(graph_reference graph, bool enabled)
|
||||
{
|
||||
nana::string text = wdg_->caption();
|
||||
std::wstring text = ::nana::charset(wdg_->caption(), ::nana::unicode::utf8);
|
||||
|
||||
nana::string::value_type shortkey;
|
||||
nana::string::size_type shortkey_pos;
|
||||
nana::string str = API::transform_shortkey_text(text, shortkey, &shortkey_pos);
|
||||
std::wstring::value_type shortkey;
|
||||
std::wstring::size_type shortkey_pos;
|
||||
std::wstring str = API::transform_shortkey_text(text, shortkey, &shortkey_pos);
|
||||
|
||||
nana::size ts = graph.text_extent_size(str);
|
||||
nana::size gsize = graph.size();
|
||||
@@ -398,14 +398,16 @@ namespace nana{ namespace drawerbase
|
||||
create(wd, rectangle(), visible);
|
||||
}
|
||||
|
||||
button::button(window wd, const nana::string& text, bool visible)
|
||||
button::button(window wd, const std::string& text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
|
||||
button::button(window wd, const nana::char_t* text, bool visible)
|
||||
button::button(window wd, const char* text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text, std::strlen(text));
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
@@ -509,12 +511,14 @@ namespace nana{ namespace drawerbase
|
||||
});
|
||||
}
|
||||
|
||||
void button::_m_caption(nana::string&& text)
|
||||
void button::_m_caption(std::string&& text)
|
||||
{
|
||||
API::unregister_shortkey(handle());
|
||||
|
||||
nana::char_t shortkey;
|
||||
API::transform_shortkey_text(text, shortkey, 0);
|
||||
std::wstring wtext = ::nana::charset(text, ::nana::unicode::utf8);
|
||||
|
||||
wchar_t shortkey;
|
||||
API::transform_shortkey_text(wtext, shortkey, 0);
|
||||
if (shortkey)
|
||||
API::register_shortkey(handle(), shortkey);
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ namespace nana
|
||||
: public float_listbox::item_interface
|
||||
{
|
||||
nana::paint::image item_image;
|
||||
nana::string item_text;
|
||||
std::string item_text;
|
||||
public:
|
||||
item(const nana::string& s)
|
||||
item(const std::string& s)
|
||||
: item_text(s)
|
||||
{}
|
||||
public:
|
||||
@@ -44,7 +44,7 @@ namespace nana
|
||||
return item_image;
|
||||
}
|
||||
|
||||
const nana::char_t * text() const override
|
||||
const char * text() const override
|
||||
{
|
||||
return item_text.data();
|
||||
}
|
||||
@@ -543,7 +543,7 @@ namespace nana
|
||||
{
|
||||
if(node)
|
||||
{
|
||||
API::dev::window_caption(window_handle(), tree().path());
|
||||
API::dev::window_caption(window_handle(), utf8_cast(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>(child->value.first));
|
||||
style_.module.items.emplace_back(std::make_shared<item>(utf8_cast(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>((*i)->value.first));
|
||||
style_.module.items.emplace_back(std::make_shared<item>(utf8_cast((*i)->value.first)));
|
||||
}
|
||||
r = style_.active_item_rectangle;
|
||||
}
|
||||
@@ -603,7 +603,7 @@ namespace nana
|
||||
case ui_element::item_arrow:
|
||||
{
|
||||
treebase_.tail(style_.active);
|
||||
nana::string name = style_.module.items[style_.module.index]->text();
|
||||
nana::string name = utf8_cast(style_.module.items[style_.module.index]->text());
|
||||
node_handle node = treebase_.find_child(name);
|
||||
if(node)
|
||||
{
|
||||
@@ -805,16 +805,17 @@ namespace nana
|
||||
delete scheme_;
|
||||
}
|
||||
|
||||
void trigger::insert(const nana::string& str, nana::any value)
|
||||
void trigger::insert(const std::string& str, nana::any value)
|
||||
{
|
||||
scheme_->tree().insert(str, value);
|
||||
API::dev::window_caption(scheme_->window_handle(), scheme_->tree().path());
|
||||
throw_not_utf8(str);
|
||||
scheme_->tree().insert(utf8_cast(str), value);
|
||||
API::dev::window_caption(scheme_->window_handle(), utf8_cast(scheme_->tree().path()));
|
||||
scheme_->draw();
|
||||
}
|
||||
|
||||
bool trigger::childset(const nana::string& str, nana::any value)
|
||||
bool trigger::childset(const std::string& str, nana::any value)
|
||||
{
|
||||
if(scheme_->tree().childset(str, value))
|
||||
if(scheme_->tree().childset(utf8_cast(str), value))
|
||||
{
|
||||
scheme_->draw();
|
||||
return true;
|
||||
@@ -822,9 +823,9 @@ namespace nana
|
||||
return false;
|
||||
}
|
||||
|
||||
bool trigger::childset_erase(const nana::string& str)
|
||||
bool trigger::childset_erase(const std::string& str)
|
||||
{
|
||||
if(scheme_->tree().childset_erase(str))
|
||||
if(scheme_->tree().childset_erase(utf8_cast(str)))
|
||||
{
|
||||
scheme_->draw();
|
||||
return true;
|
||||
@@ -852,14 +853,14 @@ namespace nana
|
||||
return scheme_->tree().splitstr();
|
||||
}
|
||||
|
||||
void trigger::path(const nana::string& str)
|
||||
void trigger::path(const std::string& str)
|
||||
{
|
||||
scheme_->tree().path(str);
|
||||
scheme_->tree().path(utf8_cast(str));
|
||||
}
|
||||
|
||||
nana::string trigger::path() const
|
||||
std::string trigger::path() const
|
||||
{
|
||||
return scheme_->tree().path();
|
||||
return utf8_cast(scheme_->tree().path());
|
||||
}
|
||||
|
||||
nana::any& trigger::value() const
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace checkbox
|
||||
{
|
||||
if (graph.width() > 16 + interval)
|
||||
{
|
||||
nana::string title = widget_->caption();
|
||||
std::wstring title = ::nana::charset(widget_->caption(), ::nana::unicode::utf8);
|
||||
|
||||
unsigned pixels = graph.width() - (16 + interval);
|
||||
|
||||
@@ -129,18 +129,16 @@ namespace checkbox
|
||||
bgcolor(API::bgcolor(wd));
|
||||
}
|
||||
|
||||
checkbox::checkbox(window wd, const nana::string& text, bool visible)
|
||||
checkbox::checkbox(window wd, const std::string& text, bool visible)
|
||||
{
|
||||
create(wd, rectangle(), visible);
|
||||
bgcolor(API::bgcolor(wd));
|
||||
caption(text);
|
||||
}
|
||||
|
||||
checkbox::checkbox(window wd, const nana::char_t* text, bool visible)
|
||||
checkbox::checkbox(window wd, const char* text, bool visible)
|
||||
: checkbox(wd, std::string(text), visible)
|
||||
{
|
||||
create(wd, rectangle(), visible);
|
||||
bgcolor(API::bgcolor(wd));
|
||||
caption(text);
|
||||
}
|
||||
|
||||
checkbox::checkbox(window wd, const nana::rectangle& r, bool visible)
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace nana
|
||||
std::shared_ptr<nana::detail::key_interface> key;
|
||||
|
||||
nana::paint::image item_image;
|
||||
nana::string item_text;
|
||||
std::string item_text;
|
||||
mutable std::shared_ptr<nana::any> any_ptr;
|
||||
|
||||
item(std::shared_ptr<nana::detail::key_interface> && kv)
|
||||
@@ -62,7 +62,7 @@ namespace nana
|
||||
{
|
||||
}
|
||||
|
||||
item(nana::string&& s)
|
||||
item(std::string&& s)
|
||||
: item_text(std::move(s))
|
||||
{}
|
||||
private:
|
||||
@@ -72,7 +72,7 @@ namespace nana
|
||||
return item_image;
|
||||
}
|
||||
|
||||
const nana::char_t* text() const override
|
||||
const char* text() const override
|
||||
{
|
||||
return item_text.data();
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace nana
|
||||
graph_ = nullptr;
|
||||
}
|
||||
|
||||
void insert(nana::string&& text)
|
||||
void insert(std::string&& text)
|
||||
{
|
||||
items_.emplace_back(std::make_shared<item>(std::move(text)));
|
||||
API::refresh_window(widget_->handle());
|
||||
@@ -338,7 +338,7 @@ namespace nana
|
||||
if (calc_where(*graph_, pos.x, pos.y))
|
||||
state_.button_state = element_state::normal;
|
||||
|
||||
editor_->text(items_[index]->item_text);
|
||||
editor_->text(::nana::charset(items_[index]->item_text, ::nana::unicode::utf8));
|
||||
_m_draw_push_button(widget_->enabled());
|
||||
_m_draw_image();
|
||||
|
||||
@@ -398,7 +398,7 @@ namespace nana
|
||||
if (pos == module_.index)
|
||||
{
|
||||
module_.index = ::nana::npos;
|
||||
this->widget_->caption(L"");
|
||||
this->widget_->caption("");
|
||||
}
|
||||
else if ((::nana::npos != module_.index) && (pos < module_.index))
|
||||
--module_.index;
|
||||
@@ -731,13 +731,14 @@ namespace nana
|
||||
pos_(pos)
|
||||
{}
|
||||
|
||||
item_proxy& item_proxy::text(const nana::string& s)
|
||||
item_proxy& item_proxy::text(const ::std::string& s)
|
||||
{
|
||||
throw_not_utf8(s);
|
||||
impl_->at(pos_).item_text = s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nana::string item_proxy::text() const
|
||||
::std::string item_proxy::text() const
|
||||
{
|
||||
return impl_->at(pos_).item_text;
|
||||
}
|
||||
@@ -767,7 +768,7 @@ namespace nana
|
||||
}
|
||||
|
||||
/// Behavior of Iterator's value_type
|
||||
bool item_proxy::operator == (const nana::string& s) const
|
||||
bool item_proxy::operator == (const ::std::string& s) const
|
||||
{
|
||||
if (pos_ == nana::npos)
|
||||
return false;
|
||||
@@ -778,17 +779,10 @@ namespace nana
|
||||
{
|
||||
if (pos_ == nana::npos)
|
||||
return false;
|
||||
return (impl_->at(pos_).item_text == static_cast<nana::string>(nana::charset(s, nana::unicode::utf8)));
|
||||
}
|
||||
|
||||
bool item_proxy::operator == (const wchar_t * s) const
|
||||
{
|
||||
if (pos_ == nana::npos)
|
||||
return false;
|
||||
|
||||
return (impl_->at(pos_).item_text == s);
|
||||
}
|
||||
|
||||
|
||||
/// Behavior of Iterator
|
||||
item_proxy & item_proxy::operator=(const item_proxy& r)
|
||||
{
|
||||
@@ -876,16 +870,16 @@ namespace nana
|
||||
create(wd, rectangle(), visible);
|
||||
}
|
||||
|
||||
combox::combox(window wd, nana::string text, bool visible)
|
||||
combox::combox(window wd, std::string text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
create(wd, rectangle(), visible);
|
||||
caption(std::move(text));
|
||||
}
|
||||
|
||||
combox::combox(window wd, const nana::char_t* text, bool visible)
|
||||
combox::combox(window wd, const char* text, bool visible)
|
||||
: combox(wd, std::string(text), visible)
|
||||
{
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
|
||||
combox::combox(window wd, const nana::rectangle& r, bool visible)
|
||||
@@ -920,7 +914,7 @@ namespace nana
|
||||
editor->set_accept(std::move(pred));
|
||||
}
|
||||
|
||||
combox& combox::push_back(nana::string text)
|
||||
combox& combox::push_back(std::string text)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
_m_impl().insert(std::move(text));
|
||||
@@ -946,7 +940,7 @@ namespace nana
|
||||
API::update_window(handle());
|
||||
}
|
||||
|
||||
nana::string combox::text(std::size_t pos) const
|
||||
::std::string combox::text(std::size_t pos) const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
return _m_impl().at(pos).item_text;
|
||||
@@ -988,20 +982,22 @@ namespace nana
|
||||
API::refresh_window(*this);
|
||||
}
|
||||
|
||||
nana::string combox::_m_caption() const throw()
|
||||
std::string combox::_m_caption() const throw()
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto editor = _m_impl().editor();
|
||||
return (editor ? editor->text() : nana::string());
|
||||
if (editor)
|
||||
return ::nana::charset(editor->text());
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void combox::_m_caption(nana::string&& str)
|
||||
void combox::_m_caption(std::string&& str)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
|
||||
auto editor = _m_impl().editor();
|
||||
if (editor)
|
||||
editor->text(std::move(str));
|
||||
editor->text(::nana::charset(str, nana::unicode::utf8));
|
||||
|
||||
API::refresh_window(*this);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace nana
|
||||
trigger::trigger()
|
||||
: widget_(nullptr), chose_(false), page_(page::date), pos_(where::none)
|
||||
{
|
||||
const nana::string ws[] = {STR("S"), STR("M"), STR("T"), STR("W"), STR("T"), STR("F"), STR("S")};
|
||||
const std::string ws[] = {"S", "M", "T", "W", "T", "F", "S"};
|
||||
for(int i = 0; i < 7; ++i) weekstr_[i] = ws[i];
|
||||
|
||||
nana::date d;
|
||||
@@ -50,8 +50,9 @@ namespace nana
|
||||
return nana::date(chdate_.year, chdate_.month, chdate_.day);
|
||||
}
|
||||
|
||||
void trigger::week_name(unsigned index, const nana::string& str)
|
||||
void trigger::week_name(unsigned index, const std::string& str)
|
||||
{
|
||||
throw_not_utf8(str);
|
||||
if(index < 7)
|
||||
this->weekstr_[index] = str;
|
||||
}
|
||||
@@ -95,13 +96,13 @@ namespace nana
|
||||
|
||||
if(graph.width() > 32 + border_size * 2)
|
||||
{
|
||||
nana::string str;
|
||||
std::string str;
|
||||
if(page_ == page::date)
|
||||
{
|
||||
str = ::nana::internationalization()(monthstr[chmonth_.month - 1]);
|
||||
str += STR(" ");
|
||||
str += " ";
|
||||
}
|
||||
str += std::to_wstring(chmonth_.year);
|
||||
str += std::to_string(chmonth_.year);
|
||||
|
||||
nana::size txt_s = graph.text_extent_size(str);
|
||||
|
||||
@@ -110,7 +111,8 @@ namespace nana
|
||||
int xpos = static_cast<int>(graph.width() - txt_s.width) / 2;
|
||||
if(xpos < border_size + 16) xpos = 16 + border_size + 1;
|
||||
|
||||
graph.string({ xpos, top }, str, (pos_ == where::topbar ? color_.highlight : color_.normal));
|
||||
graph.set_text_color(pos_ == where::topbar ? color_.highlight : color_.normal);
|
||||
graph.string({ xpos, top }, str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ namespace nana
|
||||
dbasis_ = dbasis;
|
||||
}
|
||||
|
||||
void trigger::_m_draw_pos(drawing_basis & dbasis, graph_reference graph, int x, int y, const nana::string& str, bool primary, bool sel)
|
||||
void trigger::_m_draw_pos(drawing_basis & dbasis, graph_reference graph, int x, int y, const std::string& str_utf8, bool primary, bool sel)
|
||||
{
|
||||
nana::rectangle r(static_cast<int>(x * dbasis.row_s), static_cast<int>(y * dbasis.line_s),
|
||||
static_cast<int>(dbasis.row_s), static_cast<int>(dbasis.line_s));
|
||||
@@ -165,13 +167,14 @@ namespace nana
|
||||
if(false == primary)
|
||||
color = { 0xB0, 0xB0, 0xB0 };
|
||||
|
||||
nana::size txt_s = graph.text_extent_size(str);
|
||||
graph.string({ r.x + static_cast<int>(r.width - txt_s.width) / 2, r.y + static_cast<int>(r.height - txt_s.height) / 2 }, str, color);
|
||||
nana::size txt_s = graph.text_extent_size(str_utf8);
|
||||
graph.set_text_color(color);
|
||||
graph.string({ r.x + static_cast<int>(r.width - txt_s.width) / 2, r.y + static_cast<int>(r.height - txt_s.height) / 2 }, str_utf8);
|
||||
}
|
||||
|
||||
void trigger::_m_draw_pos(drawing_basis & dbasis, graph_reference graph, int x, int y, int number, bool primary, bool sel)
|
||||
{
|
||||
_m_draw_pos(dbasis, graph, x, y, std::to_wstring(number), primary, sel);
|
||||
_m_draw_pos(dbasis, graph, x, y, std::to_string(number), primary, sel);
|
||||
}
|
||||
|
||||
void trigger::_m_draw_ex_days(drawing_basis & dbasis, graph_reference graph, int begx, int begy, bool before)
|
||||
@@ -615,16 +618,16 @@ namespace nana
|
||||
create(wd, rectangle(), visible);
|
||||
}
|
||||
|
||||
date_chooser::date_chooser(window wd, const nana::string& text, bool visible)
|
||||
date_chooser::date_chooser(window wd, const std::string& text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
|
||||
date_chooser::date_chooser(window wd, const nana::char_t* text, bool visible)
|
||||
date_chooser::date_chooser(window wd, const char* text, bool visible)
|
||||
: date_chooser(wd, std::string(text), visible)
|
||||
{
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
|
||||
date_chooser::date_chooser(window wd, const rectangle& r, bool visible)
|
||||
@@ -642,7 +645,7 @@ namespace nana
|
||||
return get_drawer_trigger().read();
|
||||
}
|
||||
|
||||
void date_chooser::weekstr(unsigned index, const nana::string& str)
|
||||
void date_chooser::weekstr(unsigned index, const ::std::string& str)
|
||||
{
|
||||
get_drawer_trigger().week_name(index, str);
|
||||
API::refresh_window(*this);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace nana{
|
||||
|
||||
implement() = default;
|
||||
|
||||
implement(window grp_panel, ::nana::string titel, bool vsb, unsigned gap=2)
|
||||
implement(window grp_panel, ::std::string titel, bool vsb, unsigned gap=2)
|
||||
: caption (grp_panel, std::move(titel), vsb),
|
||||
place_content{grp_panel},
|
||||
gap{gap}
|
||||
@@ -51,7 +51,7 @@ namespace nana{
|
||||
void create(window pnl)
|
||||
{
|
||||
caption.create(pnl);
|
||||
caption.caption(STR(""));
|
||||
caption.caption("");
|
||||
place_content.bind(pnl);
|
||||
|
||||
if (!radio_logic)
|
||||
@@ -90,7 +90,7 @@ namespace nana{
|
||||
create(parent, r, vsb);
|
||||
}
|
||||
|
||||
group::group(window parent, ::nana::string titel, bool formatted, unsigned gap, const rectangle& r, bool vsb)
|
||||
group::group(window parent, ::std::string titel, bool formatted, unsigned gap, const rectangle& r, bool vsb)
|
||||
: panel(parent, r, vsb),
|
||||
impl_(new implement(*this, std::move(titel), vsb, gap))
|
||||
{
|
||||
@@ -103,7 +103,7 @@ namespace nana{
|
||||
delete impl_->radio_logic;
|
||||
}
|
||||
|
||||
group& group::add_option(::nana::string text)
|
||||
group& group::add_option(std::string text)
|
||||
{
|
||||
_THROW_IF_EMPTY()
|
||||
|
||||
@@ -234,12 +234,12 @@ namespace nana{
|
||||
_m_init();
|
||||
}
|
||||
|
||||
::nana::string group::_m_caption() const throw()
|
||||
::std::string group::_m_caption() const throw()
|
||||
{
|
||||
return impl_->caption.caption();
|
||||
}
|
||||
|
||||
void group::_m_caption(::nana::string&& str)
|
||||
void group::_m_caption(::std::string&& str)
|
||||
{
|
||||
impl_->caption.caption(std::move(str));
|
||||
impl_->update_div();
|
||||
|
||||
@@ -772,8 +772,9 @@ namespace nana
|
||||
bgcolor(API::bgcolor(wd));
|
||||
}
|
||||
|
||||
label::label(window wd, const nana::string& text, bool visible)
|
||||
label::label(window wd, const std::string& text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
create(wd, rectangle(), visible);
|
||||
bgcolor(API::bgcolor(wd));
|
||||
caption(text);
|
||||
@@ -806,7 +807,7 @@ namespace nana
|
||||
if(impl->renderer.format(f))
|
||||
{
|
||||
window wd = *this;
|
||||
impl->renderer.parse(API::dev::window_caption(wd));
|
||||
impl->renderer.parse(::nana::charset(API::dev::window_caption(wd), ::nana::unicode::utf8));
|
||||
API::refresh_window(wd);
|
||||
}
|
||||
return *this;
|
||||
@@ -844,11 +845,12 @@ namespace nana
|
||||
return impl->renderer.measure(*graph_ptr, limited, impl->text_align, impl->text_align_v);
|
||||
}
|
||||
|
||||
::nana::size label::measure(paint::graphics& graph, const ::nana::string& str, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align)
|
||||
::nana::size label::measure(paint::graphics& graph, const ::std::string& str, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align)
|
||||
{
|
||||
throw_not_utf8(str);
|
||||
drawerbase::label::renderer rd;
|
||||
rd.format(format_enabled);
|
||||
rd.parse(str);
|
||||
rd.parse(utf8_cast(str));
|
||||
return rd.measure(graph, allowed_width_in_pixel, h_align, v_align);
|
||||
}
|
||||
|
||||
@@ -867,11 +869,11 @@ namespace nana
|
||||
return *this;
|
||||
}
|
||||
|
||||
void label::_m_caption(nana::string&& str)
|
||||
void label::_m_caption(std::string&& str)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
window wd = *this;
|
||||
get_drawer_trigger().impl()->renderer.parse(str);
|
||||
get_drawer_trigger().impl()->renderer.parse(::nana::charset(str, nana::unicode::utf8));
|
||||
API::dev::window_caption(wd, std::move(str));
|
||||
API::refresh_window(wd);
|
||||
}
|
||||
|
||||
@@ -713,7 +713,7 @@ namespace nana
|
||||
want_focus_{ (!wd) || ((!is_wd_parent_menu) && (API::focus_window() != wd)) },
|
||||
event_focus_{ nullptr }
|
||||
{
|
||||
caption(STR("nana menu window"));
|
||||
caption("nana menu window");
|
||||
get_drawer_trigger().close_menu_tree([this]{ this->_m_close_all(); });
|
||||
get_drawer_trigger().renderer = rdptr;
|
||||
state_.owner_menubar = state_.self_submenu = false;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace nana
|
||||
//class drawer
|
||||
void drawer::attached(widget_reference wdg, graph_reference)
|
||||
{
|
||||
wdg.caption(STR("panel widget"));
|
||||
wdg.caption("panel widget");
|
||||
window_ = wdg.handle();
|
||||
|
||||
API::ignore_mouse_focus(wdg, true);
|
||||
|
||||
@@ -47,10 +47,11 @@ namespace nana
|
||||
}
|
||||
}
|
||||
|
||||
virtual void adorn_textbox(window, graph_reference graph, const nana::string& str, const nana::rectangle & r)
|
||||
virtual void adorn_textbox(window, graph_reference graph, const std::string& str, const nana::rectangle & r)
|
||||
{
|
||||
graph.rectangle(r, false, colors::white);
|
||||
graph.string({ r.x + 2, r.y + 1 }, str, colors::white);
|
||||
graph.set_text_color(colors::white);
|
||||
graph.string({ r.x + 2, r.y + 1 }, str);
|
||||
}
|
||||
|
||||
virtual void slider(window, graph_reference graph, const slider_t& s)
|
||||
@@ -512,7 +513,7 @@ namespace nana
|
||||
if(proto_.provider && attr_.is_draw_adorn)
|
||||
{
|
||||
unsigned vadorn = _m_value_by_pos(attr_.adorn_pos);
|
||||
nana::string str = proto_.provider->adorn_trace(attr_.vmax, vadorn);
|
||||
auto str = proto_.provider->adorn_trace(attr_.vmax, vadorn);
|
||||
if(str.size())
|
||||
{
|
||||
nana::size ts = other_.graph->text_extent_size(str);
|
||||
|
||||
@@ -677,20 +677,22 @@ namespace nana
|
||||
modifier(static_cast<std::wstring>(::nana::charset(prefix_utf8, ::nana::unicode::utf8)), static_cast<std::wstring>(::nana::charset(suffix_utf8, ::nana::unicode::utf8)));
|
||||
}
|
||||
|
||||
::nana::string spinbox::_m_caption() const throw()
|
||||
::std::string spinbox::_m_caption() const throw()
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().impl()->editor();
|
||||
return (editor ? editor->text() : nana::string());
|
||||
if (editor)
|
||||
return ::nana::charset(editor->text());
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void spinbox::_m_caption(::nana::string&& text)
|
||||
void spinbox::_m_caption(::std::string&& text)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().impl()->editor();
|
||||
if (editor)
|
||||
{
|
||||
editor->text(std::move(text));
|
||||
editor->text(::nana::charset(text, ::nana::unicode::utf8));
|
||||
API::refresh_window(*this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,14 +209,16 @@ namespace drawerbase {
|
||||
create(wd, rectangle(), visible);
|
||||
}
|
||||
|
||||
textbox::textbox(window wd, const nana::string& text, bool visible)
|
||||
textbox::textbox(window wd, const std::string& text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
|
||||
textbox::textbox(window wd, const nana::char_t* text, bool visible)
|
||||
textbox::textbox(window wd, const char* text, bool visible)
|
||||
{
|
||||
throw_not_utf8(text, std::strlen(text));
|
||||
create(wd, rectangle(), visible);
|
||||
caption(text);
|
||||
}
|
||||
@@ -419,11 +421,12 @@ namespace drawerbase {
|
||||
editor->set_accept(std::move(fn));
|
||||
}
|
||||
|
||||
textbox& textbox::tip_string(nana::string str)
|
||||
textbox& textbox::tip_string(std::string str)
|
||||
{
|
||||
throw_not_utf8(str);
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().editor();
|
||||
if(editor && editor->tip_string(std::move(str)))
|
||||
if(editor && editor->tip_string(utf8_cast(str)))
|
||||
API::refresh_window(handle());
|
||||
return *this;
|
||||
}
|
||||
@@ -484,14 +487,10 @@ namespace drawerbase {
|
||||
|
||||
int textbox::to_int() const
|
||||
{
|
||||
nana::string s = _m_caption();
|
||||
auto s = _m_caption();
|
||||
if (s.empty()) return 0;
|
||||
|
||||
#ifdef NANA_UNICODE
|
||||
std::wstringstream ss;
|
||||
#else
|
||||
std::stringstream ss;
|
||||
#endif
|
||||
int value;
|
||||
ss << s;
|
||||
ss >> value;
|
||||
@@ -500,14 +499,10 @@ namespace drawerbase {
|
||||
|
||||
double textbox::to_double() const
|
||||
{
|
||||
nana::string s = _m_caption();
|
||||
auto s = _m_caption();
|
||||
if (s.empty()) return 0;
|
||||
|
||||
#ifdef NANA_UNICODE
|
||||
std::wstringstream ss;
|
||||
#else
|
||||
std::stringstream ss;
|
||||
#endif
|
||||
double value;
|
||||
ss << s;
|
||||
ss >> value;
|
||||
@@ -516,13 +511,13 @@ namespace drawerbase {
|
||||
|
||||
textbox& textbox::from(int n)
|
||||
{
|
||||
_m_caption(std::to_wstring(n));
|
||||
_m_caption(std::to_string(n));
|
||||
return *this;
|
||||
}
|
||||
|
||||
textbox& textbox::from(double d)
|
||||
{
|
||||
_m_caption(std::to_wstring(d));
|
||||
_m_caption(std::to_string(d));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -542,7 +537,7 @@ namespace drawerbase {
|
||||
editor->erase_highlight(name);
|
||||
}
|
||||
|
||||
void textbox::set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<nana::string> kw_list)
|
||||
void textbox::set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::wstring> kw_list)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().editor();
|
||||
@@ -600,20 +595,23 @@ namespace drawerbase {
|
||||
}
|
||||
|
||||
//Override _m_caption for caption()
|
||||
nana::string textbox::_m_caption() const throw()
|
||||
::std::string textbox::_m_caption() const throw()
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().editor();
|
||||
return (editor ? editor->text() : nana::string());
|
||||
if (editor)
|
||||
return ::nana::charset(editor->text());
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void textbox::_m_caption(nana::string&& str)
|
||||
void textbox::_m_caption(std::string&& str)
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().editor();
|
||||
if (editor)
|
||||
{
|
||||
editor->text(std::move(str));
|
||||
editor->text(::nana::charset(str, ::nana::unicode::utf8));
|
||||
API::update_window(this->handle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace nana
|
||||
|
||||
typedef std::size_t size_type;
|
||||
|
||||
nana::string text;
|
||||
std::string text;
|
||||
nana::paint::image image;
|
||||
unsigned pixels{0};
|
||||
nana::size textsize;
|
||||
@@ -39,7 +39,7 @@ namespace nana
|
||||
|
||||
kind type;
|
||||
|
||||
item_type(const nana::string& text, const nana::paint::image& img, kind type)
|
||||
item_type(const std::string& text, const nana::paint::image& img, kind type)
|
||||
:text(text), image(img), type(type)
|
||||
{}
|
||||
};
|
||||
@@ -58,9 +58,9 @@ namespace nana
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
void insert(size_type pos, const nana::string& text, const nana::paint::image& img, item_type::kind type)
|
||||
void insert(size_type pos, std::string text, const nana::paint::image& img, item_type::kind type)
|
||||
{
|
||||
item_type* m = new item_type(text, img, type);
|
||||
item_type* m = new item_type(std::move(text), img, type);
|
||||
|
||||
if(pos < cont_.size())
|
||||
cont_.insert(cont_.begin() + pos, m);
|
||||
@@ -68,12 +68,12 @@ namespace nana
|
||||
cont_.push_back(m);
|
||||
}
|
||||
|
||||
void push_back(const nana::string& text, const nana::paint::image& img)
|
||||
void push_back(const std::string& text, const nana::paint::image& img)
|
||||
{
|
||||
insert(cont_.size(), text, img, item_type::kind::button);
|
||||
}
|
||||
|
||||
void push_back(const nana::string& text)
|
||||
void push_back(const std::string& text)
|
||||
{
|
||||
insert(cont_.size(), text, nana::paint::image(), item_type::kind::button);
|
||||
}
|
||||
@@ -242,7 +242,7 @@ namespace nana
|
||||
impl_->graph_ptr = &graph;
|
||||
|
||||
widget_ = static_cast< ::nana::toolbar*>(&widget);
|
||||
widget.caption(L"Nana Toolbar");
|
||||
widget.caption("nana toolbar");
|
||||
|
||||
impl_->event_size = API::events(widget.parent()).resized.connect_unignorable([this](const arg_resized& arg)
|
||||
{
|
||||
@@ -405,13 +405,13 @@ namespace nana
|
||||
API::refresh_window(handle());
|
||||
}
|
||||
|
||||
void toolbar::append(const nana::string& text, const nana::paint::image& img)
|
||||
void toolbar::append(const std::string& text, const nana::paint::image& img)
|
||||
{
|
||||
get_drawer_trigger().items().push_back(text, img);
|
||||
API::refresh_window(handle());
|
||||
}
|
||||
|
||||
void toolbar::append(const nana::string& text)
|
||||
void toolbar::append(const std::string& text)
|
||||
{
|
||||
get_drawer_trigger().items().push_back(text, {});
|
||||
API::refresh_window(this->handle());
|
||||
|
||||
@@ -1856,7 +1856,7 @@ namespace nana
|
||||
|
||||
widget.bgcolor(colors::white);
|
||||
impl_->data.widget_ptr = static_cast< ::nana::treebox*>(&widget);
|
||||
widget.caption(STR("Nana Treebox"));
|
||||
widget.caption("nana treebox");
|
||||
}
|
||||
|
||||
void trigger::refresh(graph_reference)
|
||||
|
||||
@@ -41,12 +41,12 @@ namespace nana
|
||||
wdg_._m_notify_destroy();
|
||||
}
|
||||
|
||||
std::wstring caption() override
|
||||
std::string caption() override
|
||||
{
|
||||
return wdg_._m_caption();
|
||||
}
|
||||
|
||||
virtual void caption(std::wstring text)
|
||||
virtual void caption(std::string text)
|
||||
{
|
||||
wdg_._m_caption(std::move(text));
|
||||
}
|
||||
@@ -54,19 +54,15 @@ namespace nana
|
||||
widget& wdg_;
|
||||
};
|
||||
|
||||
nana::string widget::caption() const throw()
|
||||
std::string widget::caption() const throw()
|
||||
{
|
||||
return this->_m_caption();
|
||||
}
|
||||
|
||||
void widget::caption(std::string utf8)
|
||||
{
|
||||
_m_caption(std::wstring(::nana::charset(utf8, ::nana::unicode::utf8)));
|
||||
}
|
||||
|
||||
void widget::caption(std::wstring str)
|
||||
{
|
||||
_m_caption(std::move(str));
|
||||
::nana::throw_not_utf8(utf8);
|
||||
_m_caption(std::move(utf8));
|
||||
}
|
||||
|
||||
void widget::i18n(i18n_eval eval)
|
||||
@@ -228,7 +224,7 @@ namespace nana
|
||||
return *this;
|
||||
}
|
||||
|
||||
widget& widget::tooltip(const nana::string& text)
|
||||
widget& widget::tooltip(const ::std::string& text)
|
||||
{
|
||||
nana::tooltip::set(*this, text);
|
||||
return *this;
|
||||
@@ -252,12 +248,12 @@ namespace nana
|
||||
void widget::_m_complete_creation()
|
||||
{}
|
||||
|
||||
nana::string widget::_m_caption() const throw()
|
||||
std::string widget::_m_caption() const throw()
|
||||
{
|
||||
return API::dev::window_caption(handle());
|
||||
}
|
||||
|
||||
void widget::_m_caption(nana::string&& str)
|
||||
void widget::_m_caption(std::string&& str)
|
||||
{
|
||||
API::dev::window_caption(handle(), std::move(str));
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace nana
|
||||
|
||||
struct data
|
||||
{
|
||||
std::unordered_map<std::string, nana::string> table;
|
||||
std::unordered_map<std::string, std::string> table;
|
||||
};
|
||||
|
||||
static std::shared_ptr<data>& get_data_ptr()
|
||||
@@ -174,14 +174,14 @@ namespace nana
|
||||
if (token::string != tknizer.read())
|
||||
return;
|
||||
|
||||
nana::string str;
|
||||
std::string str;
|
||||
|
||||
if (utf8)
|
||||
str = nana::charset(std::move(tknizer.get_str()), nana::unicode::utf8);
|
||||
else
|
||||
str = nana::charset(std::move(tknizer.get_str()));
|
||||
|
||||
nana::string::size_type pos = 0;
|
||||
std::string::size_type pos = 0;
|
||||
while (true)
|
||||
{
|
||||
pos = str.find('\\', pos);
|
||||
@@ -292,21 +292,21 @@ namespace nana
|
||||
internationalization_parts::load(file, true);
|
||||
}
|
||||
|
||||
nana::string internationalization::get(std::string msgid) const
|
||||
std::string internationalization::get(std::string msgid) const
|
||||
{
|
||||
nana::string str;
|
||||
std::string str;
|
||||
if(_m_get(msgid, str))
|
||||
_m_replace_args(str, nullptr);
|
||||
return str;
|
||||
}
|
||||
|
||||
void internationalization::set(std::string msgid, nana::string msgstr)
|
||||
void internationalization::set(std::string msgid, std::string msgstr)
|
||||
{
|
||||
auto & ptr = internationalization_parts::get_data_ptr();
|
||||
ptr->table[msgid].swap(msgstr);
|
||||
}
|
||||
|
||||
bool internationalization::_m_get(std::string& msgid, nana::string& msgstr) const
|
||||
bool internationalization::_m_get(std::string& msgid, std::string& msgstr) const
|
||||
{
|
||||
auto & impl = internationalization_parts::get_data_ptr();
|
||||
auto i = impl->table.find(msgid);
|
||||
@@ -320,22 +320,22 @@ namespace nana
|
||||
return false;
|
||||
}
|
||||
|
||||
void internationalization::_m_replace_args(nana::string& str, std::vector<nana::string> * arg_strs) const
|
||||
void internationalization::_m_replace_args(std::string& str, std::vector<std::string> * arg_strs) const
|
||||
{
|
||||
nana::string::size_type offset = 0;
|
||||
std::string::size_type offset = 0;
|
||||
while (true)
|
||||
{
|
||||
auto pos = str.find(L"%arg", offset);
|
||||
auto pos = str.find("%arg", offset);
|
||||
if (pos == str.npos)
|
||||
break;
|
||||
|
||||
offset = pos;
|
||||
pos = str.find_first_not_of(L"0123456789", offset + 4);
|
||||
pos = str.find_first_not_of("0123456789", offset + 4);
|
||||
|
||||
if ((pos == str.npos) || (pos != offset + 4))
|
||||
{
|
||||
nana::string::size_type erase_n = 0;
|
||||
nana::string::size_type arg_n = str.npos;
|
||||
std::string::size_type erase_n = 0;
|
||||
std::string::size_type arg_n = str.npos;
|
||||
if (pos != str.npos)
|
||||
{
|
||||
erase_n = pos - offset;
|
||||
@@ -363,11 +363,11 @@ namespace nana
|
||||
: public eval_arg
|
||||
{
|
||||
public:
|
||||
arg_string(nana::string str)
|
||||
arg_string(std::string str)
|
||||
: str_(std::move(str))
|
||||
{}
|
||||
|
||||
nana::string eval() const override
|
||||
std::string eval() const override
|
||||
{
|
||||
return str_;
|
||||
}
|
||||
@@ -377,7 +377,7 @@ namespace nana
|
||||
return std::unique_ptr<eval_arg>(new arg_string(str_));
|
||||
}
|
||||
private:
|
||||
nana::string str_;
|
||||
std::string str_;
|
||||
};
|
||||
|
||||
class i18n_eval::arg_eval
|
||||
@@ -392,7 +392,7 @@ namespace nana
|
||||
: eval_{ std::move(eval) }
|
||||
{}
|
||||
|
||||
nana::string eval() const override
|
||||
std::string eval() const override
|
||||
{
|
||||
return eval_();
|
||||
}
|
||||
@@ -440,18 +440,18 @@ namespace nana
|
||||
return *this;
|
||||
}
|
||||
|
||||
nana::string i18n_eval::operator()() const
|
||||
std::string i18n_eval::operator()() const
|
||||
{
|
||||
if (msgid_.empty())
|
||||
return{};
|
||||
|
||||
std::vector<nana::string> arg_strs;
|
||||
std::vector<std::string> arg_strs;
|
||||
for (auto & arg : args_)
|
||||
arg_strs.emplace_back(arg->eval());
|
||||
|
||||
internationalization i18n;
|
||||
std::string msgid = msgid_; //msgid is required to be movable by i18n._m_get
|
||||
nana::string msgstr;
|
||||
std::string msgstr;
|
||||
if (i18n._m_get(msgid, msgstr))
|
||||
i18n._m_replace_args(msgstr, &arg_strs);
|
||||
return msgstr;
|
||||
|
||||
@@ -361,6 +361,12 @@ namespace paint
|
||||
return (handle_ ? font(handle_) : font_shadow_);
|
||||
}
|
||||
|
||||
::nana::size graphics::text_extent_size(const ::std::string& text) const
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
return text_extent_size(static_cast<std::wstring>(::nana::charset(text, ::nana::unicode::utf8)));
|
||||
}
|
||||
|
||||
nana::size graphics::text_extent_size(const nana::char_t* text) const
|
||||
{
|
||||
return text_extent_size(text, nana::strlen(text));
|
||||
@@ -947,6 +953,12 @@ namespace paint
|
||||
}
|
||||
}
|
||||
|
||||
void graphics::string(const point& pos, const std::string& text)
|
||||
{
|
||||
throw_not_utf8(text);
|
||||
string(pos, static_cast<std::wstring>(::nana::charset(text, ::nana::unicode::utf8)));
|
||||
}
|
||||
|
||||
void graphics::string(nana::point pos, const char_t* str, std::size_t len)
|
||||
{
|
||||
if (handle_ && str && len)
|
||||
|
||||
Reference in New Issue
Block a user