change some APIs for accepting utf8

This commit is contained in:
Jinhao
2015-11-27 01:54:26 +08:00
parent 3b8e113745
commit 12358a5dc0
55 changed files with 517 additions and 483 deletions

View File

@@ -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))