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

@ -9,9 +9,6 @@ namespace nana
utf8, utf16, utf32
};
/// Checks whether a specified text is utf8 encoding
bool is_utf8(const char* str, unsigned len);
namespace detail
{
class charset_encoding_interface;

View File

@ -72,6 +72,16 @@ namespace std
}
#endif
namespace nana
{
/// Checks whether a specified text is utf8 encoding
bool is_utf8(const char* str, unsigned len);
void throw_not_utf8(const std::string& text);
void throw_not_utf8(const char*, unsigned len);
std::wstring utf8_cast(const std::string&);
std::string utf8_cast(const std::wstring&);
}
#ifndef NANA_UNICODE
namespace nana

View File

@ -24,7 +24,7 @@ namespace filesystem
tm modified;
};
bool file_attrib(const nana::string& file, attribute&);
bool file_attrib(const ::std::string& file, attribute&);
long long filesize(const nana::string& file);
bool mkdir(const nana::string& dir, bool & if_exist);

View File

@ -145,7 +145,7 @@ namespace detail
basic_window *parent;
basic_window *owner;
::nana::string title;
::std::string title;
::nana::detail::drawer drawer; //Self Drawer with owen graphics
basic_window* root_widget; //A pointer refers to the root basic window, if the window is a root, the pointer refers to itself.
paint::graphics* root_graph; //Refer to the root buffer graphics

View File

@ -65,8 +65,8 @@ namespace detail
static void window_size(native_window_type, const size&);
static void get_window_rect(native_window_type, rectangle&);
static void window_caption(native_window_type, const nana::string&);
static nana::string window_caption(native_window_type);
static void window_caption(native_window_type, const std::string&);
static std::string window_caption(native_window_type);
static void capture_window(native_window_type, bool);
static nana::point cursor_position();
static native_window_type get_owner_window(native_window_type);

View File

@ -30,8 +30,8 @@ namespace nana
virtual widget* widget_ptr() const = 0;
virtual void destroy() = 0;
virtual std::wstring caption() = 0;
virtual void caption(std::wstring) = 0;
virtual std::string caption() = 0;
virtual void caption(std::string) = 0;
};
}
}

View File

@ -25,7 +25,7 @@ namespace nana
filebox(filebox&&) = delete;
filebox& operator=(filebox&&) = delete;
public:
using filters = std::vector<std::pair<nana::string, nana::string>>;
using filters = std::vector<std::pair< ::std::string, ::std::string>>;
filebox(bool is_open_mode);
filebox(window owner, bool is_open_mode);
@ -37,21 +37,21 @@ namespace nana
/// Change owner window
void owner(window);
/** @brief specify a title for the dialog
* @param string a text for title
*/
nana::string title( nana::string new_title); ///< . Set a new title for the dialog and \return the old title
/// specify a title for the dialog
/// @param string a text for title
/// @return old title.
::std::string title( ::std::string new_title); ///< . Set a new title for the dialog and \return the old title
/** @brief specify a suggestion directory
* @param string a path of initial directory
* @note the behavior of init_path is different between Win7 and Win2K/XP/Vista, but its behavior under Linux is conformed with Win7.
*/
filebox& init_path(const nana::string&); ///< Suggested init path used to locate a directory when the filebox starts.
filebox& init_file(const nana::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file.
filebox& init_path(const ::std::string&); ///< Suggested init path used to locate a directory when the filebox starts.
filebox& init_file(const ::std::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file.
/// \brief Add a filetype filter.
/// To specify multiple filter in a single description, use a semicolon to separate the patterns(for example,"*.TXT;*.DOC;*.BAK").
filebox& add_filter(const nana::string& description, ///< for example. "Text File"
const nana::string& filetype ///< filter pattern(for example, "*.TXT")
filebox& add_filter(const ::std::string& description, ///< for example. "Text File"
const ::std::string& filetype ///< filter pattern(for example, "*.TXT")
);
filebox& add_filter(const filters &ftres)
@ -62,16 +62,14 @@ namespace nana
};
nana::string path() const;
nana::string file() const;
::std::string path() const;
::std::string file() const;
/** @brief Display the filebox dialog
*/
/// Display the filebox dialog
bool show() const;
/** @brief Display the filebox dialog
* @note A function object method alternative to show()
*/
/// Display the filebox dialog
/// A function object method alternative to show()
bool operator()() const
{
return show();

View File

@ -43,10 +43,10 @@ namespace nana
msgbox& operator=(const msgbox&);
/// Construct that creates a message box with a specified title and default button.
msgbox(const nana::string&);
msgbox(const ::std::string&);
/// Construct that creates a message box with an owner windoow, a specified title and buttons.
msgbox(window, const nana::string&, button_t = ok);
msgbox(window, const ::std::string&, button_t = ok);
/// Sets an icon for informing user.
msgbox& icon(icon_t);
@ -86,7 +86,7 @@ namespace nana
private:
std::stringstream sstream_;
window wd_;
nana::string title_;
std::string title_;
button_t button_;
icon_t icon_;
};
@ -97,7 +97,7 @@ namespace nana
{
virtual ~abstract_content() = default;
virtual const ::nana::string& label() const = 0;
virtual const ::std::string& label() const = 0;
virtual window create(window, unsigned label_px) = 0;
virtual unsigned fixed_pixels() const;
};
@ -107,13 +107,13 @@ namespace nana
{
struct implement;
public:
integer(::nana::string label, int init_value, int begin, int last, int step);
integer(::std::string label, int init_value, int begin, int last, int step);
~integer();
int value() const;
private:
//Implementation of abstract_content
const ::nana::string& label() const override;
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
private:
std::unique_ptr<implement> impl_;
@ -124,13 +124,13 @@ namespace nana
{
struct implement;
public:
real(::nana::string label, double init_value, double begin, double last, double step);
real(::std::string label, double init_value, double begin, double last, double step);
~real();
double value() const;
private:
//Implementation of abstract_content
const ::nana::string& label() const override;
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
private:
std::unique_ptr<implement> impl_;
@ -144,8 +144,8 @@ namespace nana
text(const text&) = delete;
text& operator=(const text&) = delete;
public:
text(::nana::string label, ::nana::string init_text = ::nana::string());
text(::nana::string label, std::vector<::nana::string>);
text(::std::string label, ::std::string init_text = ::std::string());
text(::std::string label, std::vector<::std::string>);
~text();
@ -154,10 +154,10 @@ namespace nana
void mask_character(wchar_t ch);
::nana::string value() const;
::std::string value() const;
private:
//Implementation of abstract_content
const ::nana::string& label() const override;
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
private:
std::unique_ptr<implement> impl_;
@ -168,17 +168,17 @@ namespace nana
{
struct implement;
public:
date(::nana::string label);
date(::std::string label);
~date();
::nana::string value() const;
::std::string value() const;
int year() const;
int month() const; //[1, 12]
int day() const; //[1, 31]
private:
//Implementation of abstract_content
const ::nana::string& label() const override;
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
unsigned fixed_pixels() const override;
private:
@ -190,19 +190,19 @@ namespace nana
{
struct implement;
public:
path(::nana::string label, const ::nana::filebox&);
path(::std::string label, const ::nana::filebox&);
~path();
::nana::string value() const;
::std::string value() const;
private:
//Implementation of abstract_content
const ::nana::string& label() const override;
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
private:
std::unique_ptr<implement> impl_;
};
inputbox(window, ::nana::string description, ::nana::string title = ::nana::string());
inputbox(window, ::std::string description, ::std::string title = ::std::string());
void image(::nana::paint::image, bool is_left, const rectangle& valid_area = {});
void image_v(::nana::paint::image, bool is_top, const rectangle& valid_area = {});
@ -246,8 +246,8 @@ namespace nana
bool _m_open(std::vector<abstract_content*>&, bool modal);
private:
window owner_;
::nana::string description_;
::nana::string title_;
::std::string description_;
::std::string title_;
std::function<bool(window)> verifier_;
::nana::paint::image images_[4];
::nana::rectangle valid_areas_[4];

View File

@ -42,13 +42,17 @@ namespace nana
: init_(std::move(initializer))
{}
agent(const nana::char_t* text)
agent(const char* text)
: text_(text)
{}
{
throw_not_utf8(text);
}
agent(nana::string text, std::function<void(Widget&)> initializer = {})
agent(std::string text, std::function<void(Widget&)> initializer = {})
: text_(std::move(text)), init_(std::move(initializer))
{}
{
throw_not_utf8(text_);
}
private:
std::unique_ptr<nana::widget> create(nana::window handle) const override
@ -60,7 +64,7 @@ namespace nana
return std::move(ptr);
}
private:
nana::string text_;
std::string text_;
std::function<void(Widget&)> init_;
};
@ -79,8 +83,8 @@ namespace nana
public:
field_interface() = default;
virtual ~field_interface() = default;
virtual field_interface& operator<<(const nana::char_t* label) = 0;
virtual field_interface& operator<<(nana::string label) = 0;
virtual field_interface& operator<<(const char* label) = 0;
virtual field_interface& operator<<(std::string label) = 0;
virtual field_interface& operator<<(window) = 0;
virtual field_interface& fasten(window) = 0;

View File

@ -72,8 +72,8 @@ namespace API
widget_colors* get_scheme(window);
void attach_drawer(widget&, drawer_trigger&);
nana::string window_caption(window) throw();
void window_caption(window, nana::string);
std::string window_caption(window) throw();
void window_caption(window, std::string);
window create_window(window, bool nested, const rectangle&, const appearance&, widget* attached);
window create_widget(window, const rectangle&, widget* attached);
@ -272,7 +272,7 @@ namespace API
void window_caption(window, const std::string& title_utf8);
void window_caption(window, const nana::string& title);
nana::string window_caption(window);
::std::string window_caption(window);
void window_cursor(window, cursor);
cursor window_cursor(window);

View File

@ -24,7 +24,7 @@ namespace nana
virtual bool tooltip_empty() const = 0;
virtual nana::size tooltip_size() const = 0;
virtual void tooltip_text(const nana::string&) = 0;
virtual void tooltip_text(const ::std::string&) = 0;
virtual void tooltip_move(const nana::point& screen_pos, bool ignore_pos) = 0;
virtual void duration(std::size_t) = 0;
};
@ -63,11 +63,11 @@ namespace nana
}
tooltip(){}
tooltip(window w, const nana::string &tip){set(w,tip);}
tooltip(window w, const ::std::string &tip){set(w,tip);}
static void set(window, const nana::string&);
static void show(window, point pos, const nana::string&, std::size_t duration);
static void set(window, const ::std::string&);
static void show(window, point pos, const ::std::string&, std::size_t duration);
static void close();
private:
static void _m_hold_factory(factory_interface*);

View File

@ -83,8 +83,8 @@ namespace nana{
public:
button();
button(window, bool visible);
button(window, const nana::string& caption, bool visible = true);
button(window, const nana::char_t* caption, bool visible = true);
button(window, const ::std::string& caption, bool visible = true);
button(window, const char* caption, bool visible = true);
button(window, const nana::rectangle& = rectangle(), bool visible = true);
button& icon(const nana::paint::image&);
@ -104,7 +104,7 @@ namespace nana{
private:
//Overrides widget virtual functions
void _m_complete_creation() override;
void _m_caption(nana::string&&) override;
void _m_caption(std::string&&) override;
};
}//end namespace nana
#endif

View File

@ -108,9 +108,9 @@ namespace nana
trigger();
~trigger();
void insert(const nana::string&, nana::any);
bool childset(const nana::string&, nana::any);
bool childset_erase(const nana::string&);
void insert(const ::std::string&, nana::any);
bool childset(const ::std::string&, nana::any);
bool childset_erase(const ::std::string&);
bool clear();
//splitstr
@ -118,8 +118,8 @@ namespace nana
void splitstr(const nana::string&);
const nana::string& splitstr() const;
void path(const nana::string&);
nana::string path() const;
void path(const ::std::string&);
::std::string path() const;
template<typename T>
void create_event_agent(::nana::categorize<T>& wdg)
@ -189,7 +189,7 @@ namespace nana
/// Insert a new category with a specified name and the object of value type.
/// The new category would be inserted as a child in current category,
/// and after inserting, the new category is replaced of the current category as a new current one.
categorize& insert(const nana::string& name, const value_type& value)
categorize& insert(const std::string& name, const value_type& value)
{
this->get_drawer_trigger().insert(name, value);
API::update_window(*this);
@ -197,8 +197,9 @@ namespace nana
}
/// Inserts a child category into current category.
categorize& childset(const nana::string& name, const value_type& value)
categorize& childset(const std::string& name, const value_type& value)
{
throw_not_utf8(name);
if(this->get_drawer_trigger().childset(name, value))
API::update_window(*this);
return *this;
@ -237,7 +238,7 @@ namespace nana
}
private:
//Overrides widget's virtual functions
void _m_caption(nana::string&& str) override
void _m_caption(std::string&& str) override
{
this->get_drawer_trigger().path(str);
API::dev::window_caption(*this, this->get_drawer_trigger().path());

View File

@ -56,8 +56,8 @@ namespace drawerbase
public:
checkbox();
checkbox(window, bool visible);
checkbox(window, const nana::string& text, bool visible = true);
checkbox(window, const nana::char_t* text, bool visible = true);
checkbox(window, const std::string& text, bool visible = true);
checkbox(window, const char* text, bool visible = true);
checkbox(window, const rectangle& = rectangle(), bool visible = true);
void element_set(const char* name);

View File

@ -75,8 +75,8 @@ namespace nana
{
public:
item_proxy(drawer_impl*, std::size_t pos);
item_proxy& text(const nana::string&);
nana::string text() const;
item_proxy& text(const ::std::string&);
::std::string text() const;
item_proxy& select();
bool selected() const;
item_proxy& icon(const nana::paint::image&);
@ -112,14 +112,13 @@ namespace nana
template<typename T>
item_proxy& value(T&& t)
{
*_m_anyobj(true) = std::move(t);
*_m_anyobj(true) = ::std::move(t);
return *this;
}
public:
/// Behavior of Iterator's value_type
bool operator==(const nana::string&) const;
bool operator==(const ::std::string&) const;
bool operator==(const char*) const;
bool operator==(const wchar_t*) const;
/// Behavior of Iterator
item_proxy & operator=(const item_proxy&);
@ -166,19 +165,19 @@ namespace nana
combox();
combox(window, bool visible);
combox(window, nana::string, bool visible = true);
combox(window, const nana::char_t*, bool visible = true);
combox(window, ::std::string, bool visible = true);
combox(window, const char*, bool visible = true);
combox(window, const rectangle& r = rectangle(), bool visible = true);
void clear();
void editable(bool);
bool editable() const;
void set_accept(std::function<bool(nana::char_t)>);
combox& push_back(nana::string);
combox& push_back(std::string);
std::size_t the_number_of_options() const;
std::size_t option() const; ///< Index of the last selected, from drop-down list, item.
void option(std::size_t); ///< Select the text specified by index
nana::string text(std::size_t) const;
::std::string text(std::size_t) const;
void erase(std::size_t pos);
template<typename Key>
@ -224,8 +223,8 @@ namespace nana
const drawerbase::combox::drawer_impl& _m_impl() const;
private:
//Overrides widget's virtual functions
nana::string _m_caption() const throw() override;
void _m_caption(nana::string&&) override;
::std::string _m_caption() const throw() override;
void _m_caption(::std::string&&) override;
nana::any * _m_anyobj(std::size_t pos, bool alloc_if_empty) const override;
};
}

View File

@ -42,12 +42,12 @@ namespace nana
trigger();
bool chose() const;
nana::date read() const;
void week_name(unsigned index, const nana::string&);
void week_name(unsigned index, const std::string&);
private:
where _m_pos_where(graph_reference, const ::nana::point& pos);
void _m_draw_topbar(graph_reference);
void _m_make_drawing_basis(drawing_basis&, graph_reference, const nana::point& refpos);
void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, const nana::string&, bool primary, bool sel);
void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, const ::std::string&, bool primary, bool sel);
void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, int number, bool primary, bool sel);
void _m_draw_ex_days(drawing_basis &, graph_reference, int begx, int begy, bool before);
void _m_draw_days(const nana::point& refpos, graph_reference);
@ -61,7 +61,7 @@ namespace nana
void mouse_leave(graph_reference, const arg_mouse&) override;
void mouse_up(graph_reference, const arg_mouse&) override;
private:
nana::string weekstr_[7];
::std::string weekstr_[7];
widget * widget_;
@ -105,13 +105,13 @@ namespace nana
public:
date_chooser();
date_chooser(window, bool visible);
date_chooser(window, const nana::string& text, bool visible = true);
date_chooser(window, const nana::char_t* text, bool visible = true);
date_chooser(window, const ::std::string& text, bool visible = true);
date_chooser(window, const char* text, bool visible = true);
date_chooser(window, const nana::rectangle& r = rectangle(), bool visible = true);
bool chose() const;
nana::date read() const;
void weekstr(unsigned index, const nana::string&);///<Set the week strings which will be displayed for day, index is in range of [0, 6]
void weekstr(unsigned index, const ::std::string&);///<Set the week strings which will be displayed for day, index is in range of [0, 6]
};
}//end namespace nana

View File

@ -28,7 +28,7 @@ namespace nana
virtual ~item_interface(){}
virtual const nana::paint::image & image() const = 0;
virtual const nana::char_t* text() const = 0;
virtual const char* text() const = 0;
};
//struct module_def

View File

@ -37,7 +37,7 @@ namespace nana{
/// The construction that creates the widget and set the titel or caption
group(window parent, ///< a handle to the parent
::nana::string titel, ///< caption of the group
::std::string titel, ///< caption of the group
bool formatted = false, ///< Enable/disable the formatted text for the title
unsigned gap = 2, ///< betwen the content and the external limit
const rectangle& r = {} ,
@ -49,7 +49,7 @@ namespace nana{
~group();
/// Adds an option for user selection
group& add_option(::nana::string);
group& add_option(::std::string);
/// Enables/disables the radio mode which is single selection
group& radio_mode(bool);
@ -77,8 +77,8 @@ namespace nana{
void _m_add_child(const char* field, widget*);
void _m_init();
void _m_complete_creation() override;
::nana::string _m_caption() const throw() override;
void _m_caption(::nana::string&&) override;
::std::string _m_caption() const throw() override;
void _m_caption(::std::string&&) override;
private:
std::unique_ptr<implement> impl_;
};

View File

@ -57,8 +57,8 @@ namespace nana
typedef drawerbase::label::command command;
label();
label(window, bool visible);
label(window, const nana::string& text, bool visible = true);
label(window parent, const nana::char_t* text, bool visible = true) :label(parent, nana::string(text),visible) {};
label(window, const std::string& text, bool visible = true);
label(window parent, const char* text, bool visible = true) :label(parent, std::string(text),visible) {};
label(window, const rectangle& = {}, bool visible = true);
label& transparent(bool); ///< Switchs the label widget to the transparent background mode.
bool transparent() const throw();
@ -71,12 +71,12 @@ namespace nana
/// "corrected" size that changes lines to fit the text into the specified width
nana::size measure(unsigned allowed_width_in_pixel) const;
static ::nana::size measure(::nana::paint::graphics&, const ::nana::string&, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align);
static ::nana::size measure(::nana::paint::graphics&, const ::std::string&, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align);
label& text_align(align horizontal_align, align_v vertical_align= align_v::top);
private:
//Overrides widget's virtual function
void _m_caption(nana::string&&) override;
void _m_caption(std::string&&) override;
};
}//end namespace nana
#endif

View File

@ -186,7 +186,7 @@ namespace nana
{
graph_ = &graph;
widget_ = static_cast< ::nana::scroll<Vertical>*>(&widget);
widget.caption(STR("Nana Scroll"));
widget.caption("nana scroll");
timer_.stop();
timer_.elapse(std::bind(&trigger::_m_tick, this));

View File

@ -45,7 +45,7 @@ namespace nana
{
public:
virtual ~provider() = default;
virtual nana::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0;
virtual std::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0;
};
class renderer
@ -81,7 +81,7 @@ namespace nana
virtual void background(window, graph_reference, bool isglass) = 0;
virtual void adorn(window, graph_reference, const adorn_t&) = 0;
virtual void adorn_textbox(window, graph_reference, const nana::string&, const nana::rectangle&) = 0;
virtual void adorn_textbox(window, graph_reference, const ::std::string&, const nana::rectangle&) = 0;
virtual void bar(window, graph_reference, const bar_t&) = 0;
virtual void slider(window, graph_reference, const slider_t&) = 0;
};

View File

@ -106,8 +106,8 @@ namespace nana
void modifier(std::wstring prefix, std::wstring suffix);
void modifier(const std::string & prefix_utf8, const std::string& suffix_utf8);
private:
::nana::string _m_caption() const throw();
void _m_caption(::nana::string&&);
::std::string _m_caption() const throw();
void _m_caption(::std::string&&);
}; //end class spinbox
}//end namespace nana

View File

@ -111,13 +111,13 @@ namespace nana
/// @param window A handle to the parent window of the widget being created.
/// @param text the text that will be displayed.
/// @param visible specifying the visible after creating.
textbox(window, const nana::string& text, bool visible = true);
textbox(window, const std::string& text, bool visible = true);
/// \brief The construct that creates a widget with a specified text.
/// @param window A handle to the parent window of the widget being created.
/// @param text the text that will be displayed.
/// @param visible specifying the visible after creating.
textbox(window, const nana::char_t* text, bool visible = true);
textbox(window, const char* text, bool visible = true);
/// \brief The construct that creates a widget.
/// @param window A handle to the parent window of the widget being created.
@ -173,7 +173,7 @@ namespace nana
textbox& editable(bool);
void set_accept(std::function<bool(nana::char_t)>);
textbox& tip_string(nana::string);
textbox& tip_string(::std::string);
/// Set a mask character. Text is displayed as mask character if a mask character is set. This is used for hiding some special text, such as password.
textbox& mask(nana::char_t);
@ -195,11 +195,10 @@ namespace nana
void set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor);
void erase_highlight(const std::string& name);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<nana::string> kw_list);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::wstring> kw_list);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8);
void erase_keyword(const nana::string& kw);
/// Returns the text position of each line that currently displays on screen.
text_positions text_position() const;
@ -210,8 +209,8 @@ namespace nana
unsigned line_pixels() const;
protected:
//Overrides widget's virtual functions
::nana::string _m_caption() const throw() override;
void _m_caption(::nana::string&&) override;
::std::string _m_caption() const throw() override;
void _m_caption(::std::string&&) override;
void _m_typeface(const paint::font&) override;
};
}//end namespace nana

View File

@ -87,8 +87,8 @@ namespace nana
toolbar(window, const rectangle& = rectangle(), bool visible = true);
void separate(); ///< Adds a separator.
void append(const nana::string& text, const nana::paint::image& img); ///< Adds a control button.
void append(const nana::string& text); ///< Adds a control button.
void append(const ::std::string& text, const nana::paint::image& img); ///< Adds a control button.
void append(const ::std::string& text); ///< Adds a control button.
bool enable(size_type index) const;
void enable(size_type index, bool enable_state);
void scale(unsigned s); ///< Sets the scale of control button.

View File

@ -41,9 +41,8 @@ namespace nana
window parent() const;
nana::string caption() const throw();
::std::string caption() const throw();
void caption(std::string utf8);
void caption(std::wstring);
template<typename ...Args>
void i18n(std::string msgid, Args&&... args)
@ -91,7 +90,7 @@ namespace nana
widget& register_shortkey(char_t); ///< Registers a shortkey. To remove a registered key, pass 0.
widget& take_active(bool activated, window take_if_not_activated);
widget& tooltip(const nana::string&);
widget& tooltip(const ::std::string&);
operator dummy_bool_type() const;
operator window() const;
@ -105,8 +104,8 @@ namespace nana
virtual void _m_complete_creation();
virtual general_events& _m_get_general_events() const = 0;
virtual nana::string _m_caption() const throw();
virtual void _m_caption(nana::string&&);
virtual ::std::string _m_caption() const throw();
virtual void _m_caption(::std::string&&);
virtual nana::cursor _m_cursor() const;
virtual void _m_cursor(nana::cursor);
virtual void _m_close();

View File

@ -28,34 +28,34 @@ namespace nana
void load_utf8(const std::string& file);
template<typename ...Args>
nana::string get(std::string msgid_utf8, Args&&... args) const
::std::string get(std::string msgid_utf8, Args&&... args) const
{
std::vector<nana::string> arg_strs;
std::vector<std::string> arg_strs;
_m_fetch_args(arg_strs, std::forward<Args>(args)...);
nana::string msgstr;
::std::string msgstr;
if (_m_get(msgid_utf8, msgstr))
_m_replace_args(msgstr, &arg_strs);
return msgstr;
}
nana::string get(std::string msgid_utf8) const;
void set(std::string msgid_utf8, nana::string msgstr);
::std::string get(std::string msgid_utf8) const;
void set(std::string msgid_utf8, ::std::string msgstr);
template<typename ...Args>
nana::string operator()(std::string msgid_utf8, Args&&... args) const
::std::string operator()(std::string msgid_utf8, Args&&... args) const
{
return get(msgid_utf8, std::forward<Args>(args)...);
}
private:
bool _m_get(std::string& msgid, nana::string& msgstr) const;
void _m_replace_args(nana::string& str, std::vector<nana::string> * arg_strs) const;
bool _m_get(std::string& msgid, ::std::string& msgstr) const;
void _m_replace_args(::std::string& str, std::vector<::std::string> * arg_strs) const;
void _m_fetch_args(std::vector<nana::string>&) const //Termination of _m_fetch_args
void _m_fetch_args(std::vector<std::string>&) const //Termination of _m_fetch_args
{}
template<typename Arg>
void _m_fetch_args(std::vector<nana::string>& v, Arg&& arg) const
void _m_fetch_args(std::vector<std::string>& v, Arg&& arg) const
{
std::wstringstream ss;
ss << arg;
@ -63,52 +63,39 @@ namespace nana
}
template<typename ...Args>
void _m_fetch_args(std::vector<nana::string>& v, const char* arg, Args&&... args) const
void _m_fetch_args(std::vector<std::string>& v, const char* arg, Args&&... args) const
{
std::wstringstream ss;
ss << nana::string(nana::charset(arg));
v.emplace_back(ss.str());
v.emplace_back(arg);
_m_fetch_args(v, std::forward<Args>(args)...);
}
template<typename ...Args>
void _m_fetch_args(std::vector<nana::string>& v, const std::string& arg, Args&&... args) const
void _m_fetch_args(std::vector<std::string>& v, const std::string& arg, Args&&... args) const
{
std::wstringstream ss;
ss << nana::string(nana::charset(arg));
v.emplace_back(ss.str());
v.emplace_back(arg);
_m_fetch_args(v, std::forward<Args>(args)...);
}
template<typename ...Args>
void _m_fetch_args(std::vector<nana::string>& v, std::string& arg, Args&&... args) const
void _m_fetch_args(std::vector<std::string>& v, std::string& arg, Args&&... args) const
{
std::wstringstream ss;
ss << nana::string(nana::charset(arg));
v.emplace_back(ss.str());
v.emplace_back(arg);
_m_fetch_args(v, std::forward<Args>(args)...);
}
template<typename ...Args>
void _m_fetch_args(std::vector<nana::string>& v, std::string&& arg, Args&&... args) const
void _m_fetch_args(std::vector<std::string>& v, std::string&& arg, Args&&... args) const
{
std::wstringstream ss;
ss << nana::string(nana::charset(arg));
v.emplace_back(ss.str());
v.emplace_back(std::move(arg));
_m_fetch_args(v, std::forward<Args>(args)...);
}
template<typename Arg, typename ...Args>
void _m_fetch_args(std::vector<nana::string>& v, Arg&& arg, Args&&... args) const
void _m_fetch_args(std::vector<std::string>& v, Arg&& arg, Args&&... args) const
{
std::wstringstream ss;
std::stringstream ss;
ss << arg;
v.emplace_back(ss.str());
_m_fetch_args(v, std::forward<Args>(args)...);
}
};//end class internationalization
@ -119,7 +106,7 @@ namespace nana
{
public:
virtual ~eval_arg() = default;
virtual nana::string eval() const = 0;
virtual std::string eval() const = 0;
virtual std::unique_ptr<eval_arg> clone() const = 0;
};
@ -134,7 +121,7 @@ namespace nana
: fn_(fn)
{}
nana::string eval() const override
std::string eval() const override
{
std::wstringstream ss;
ss << fn_();
@ -166,7 +153,7 @@ namespace nana
i18n_eval& operator=(const i18n_eval&);
i18n_eval& operator=(i18n_eval&& rhs);
nana::string operator()() const;
std::string operator()() const;
private:
void _m_fetch_args(){} //Termination of _m_fetch_args
@ -180,7 +167,7 @@ namespace nana
template<typename Arg>
void _m_add_args(Arg&& arg)
{
std::wstringstream ss;
std::stringstream ss;
ss << arg;
_m_add_args(ss.str());
}

View File

@ -89,12 +89,13 @@ namespace nana
void resize(const ::nana::size&);
void typeface(const font&); ///< Selects a specified font type into the graphics object.
font typeface() const;
::nana::size text_extent_size(const ::std::string&) const;
::nana::size text_extent_size(const char_t*) const; ///< Computes the width and height of the specified string of text.
::nana::size text_extent_size(const string&) const; ///< Computes the width and height of the specified string of text.
::nana::size text_extent_size(const ::std::wstring&) const; ///< Computes the width and height of the specified string of text.
::nana::size text_extent_size(const char_t*, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length.
::nana::size text_extent_size(const string&, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length.
::nana::size text_extent_size(const ::std::wstring&, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length.
::nana::size glyph_extent_size(const char_t*, std::size_t length, std::size_t begin, std::size_t end) const;
::nana::size glyph_extent_size(const string&, std::size_t length, std::size_t begin, std::size_t end) const;
::nana::size glyph_extent_size(const ::std::wstring&, std::size_t length, std::size_t begin, std::size_t end) const;
bool glyph_pixels(const char_t *, std::size_t length, unsigned* pxbuf) const;
::nana::size bidi_extent_size(const std::wstring&) const;
::nana::size bidi_extent_size(const std::string&) const;
@ -150,6 +151,7 @@ namespace nana
void set_pixel(int x, int y, const ::nana::color&);
void set_pixel(int x, int y);
void string(const point&, const std::string&);
void string(point, const char_t*, std::size_t len);
void string(const point&, const char_t*);
void string(const point&, const ::nana::string&);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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());
}
}

View File

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

View File

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

View File

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

View File

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

View File

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