use UTF-8 for string representation

This commit is contained in:
Jinhao
2015-12-31 01:09:52 +08:00
parent 0a396c12c2
commit a42ebe19b4
38 changed files with 182 additions and 416 deletions

View File

@@ -1,7 +1,7 @@
/*
* The Deploy Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -134,51 +134,11 @@ namespace nana
detail::native_string_type to_nstring(std::size_t);
}
#ifndef NANA_UNICODE
namespace nana
{
typedef char char_t;
typedef std::string string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE
}
#else
namespace nana
{
typedef wchar_t char_t;
typedef std::wstring string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE
}
#endif
namespace nana
{
std::size_t strlen(const char_t* str);
char_t* strcpy(char_t* dest, const char_t* source);
#ifdef _MSC_VER
template <size_t N>
inline char* strcpy(char (&dest)[N], const char* source)
{
::strncpy_s(dest, source, _TRUNCATE);
return dest;
}
template <size_t N>
inline wchar_t* strcpy(wchar_t (&dest)[N], const wchar_t* source)
{
::wcsncpy_s(dest, source, _TRUNCATE);
return dest;
}
#endif // #ifdef _MSC_VER
}
#if defined(NANA_WINDOWS)
#define NANA_SHARED_EXPORT extern "C" _declspec(dllexport)
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#define NANA_SHARED_EXPORT extern "C"
#endif
namespace nana
{
inline unsigned make_rgb(unsigned char red, unsigned char green, unsigned char blue)
{
return ((unsigned(red) << 16)|((unsigned(green)<<8))|blue);
}
}

View File

@@ -102,7 +102,7 @@ namespace detail
#if defined(NANA_UNICODE)
XftDraw * xftdraw{nullptr};
XftColor xft_fgcolor;
const std::string charset(const nana::string& str, const std::string& strcode);
const std::string charset(const std::wstring& str, const std::string& strcode);
#endif
drawable_impl_type();
~drawable_impl_type();

View File

@@ -279,7 +279,7 @@ namespace filesystem
(FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY,
wfd_.nFileSizeLow);
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
#elif defined(NANA_POSIX)
if(path_.size() && (path_[path_.size() - 1] != '/'))
path_ += '/';
find_handle_t handle = opendir(path_.c_str());
@@ -307,7 +307,7 @@ namespace filesystem
is_directory = (0 != S_ISDIR(fst.st_mode));
size = fst.st_size;
}
value_ = value_type(static_cast<nana::string>(nana::charset(dnt->d_name)), is_directory, size);
value_ = value_type(static_cast<std::wstring>(nana::charset(dnt->d_name)), is_directory, size);
end_ = false;
}
}
@@ -354,7 +354,7 @@ namespace filesystem
}
}
nana::string d_name = nana::charset(dnt->d_name);
std::wstring d_name = nana::charset(dnt->d_name, nana::unicode::utf8);
struct stat fst;
if(stat((path_ + "/" + dnt->d_name).c_str(), &fst) == 0)
value_ = value_type(std::move(d_name), (0 != S_ISDIR(fst.st_mode)), fst.st_size);
@@ -433,7 +433,6 @@ namespace filesystem
std::uintmax_t file_size(const path& p);
//uintmax_t file_size(const path& p, error_code& ec) noexcept;
//long long filesize(const nana::string& file);
bool create_directories(const path& p);
@@ -442,14 +441,6 @@ namespace filesystem
//bool create_directory(const path& p, error_code& ec) noexcept;
bool create_directory(const path& p, const path& attributes);
//bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept;
/*
bool create_directory(const std::wstring& p, bool & if_exist); //deprecated
inline bool create_directory(const path& p, bool & if_exist)
{
return create_directory(p.filename(), if_exist);
}
*/
bool modified_file_time(const std::wstring& file, struct tm&);
path path_user();
@@ -458,7 +449,6 @@ namespace filesystem
//path current_path(error_code& ec);
void current_path(const path& p);
//void current_path(const path& p, error_code& ec) noexcept;
//nana::string path_current();
//bool remove(const path& p);

View File

@@ -27,37 +27,10 @@ namespace filesystem
bool modified_file_time(const ::std::string& file, struct tm&);
std::wstring path_user();
std::wstring path_current();
bool rmfile(const char* file_utf8);
bool rmdir(const char* dir, bool fails_if_not_empty);
nana::string root(const nana::string& path);
/*
class path
{
public:
struct type
{ enum{not_exist, file, directory};
};
path();
path(const nana::string&);
bool empty() const;
path root() const;
int what() const;
nana::string name() const;
private:
#if defined(NANA_WINDOWS)
nana::string text_;
#else
std::string text_;
#endif
};
*/
}//end namespace filesystem
}//end namespace nana

View File

@@ -172,7 +172,7 @@ namespace nana
void clear();
void editable(bool);
bool editable() const;
void set_accept(std::function<bool(nana::char_t)>);
void set_accept(std::function<bool(wchar_t)>);
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.

View File

@@ -63,7 +63,7 @@ namespace nana
label& transparent(bool); ///< Switchs the label widget to the transparent background mode.
bool transparent() const throw();
label& format(bool); ///< Switches the format mode of the widget.
label& add_format_listener(std::function<void(command, const nana::string&)>);
label& add_format_listener(std::function<void(command, const std::string&)>);
label& click_for(window associated_window) throw(); // as same as the "for" attribute of a label

View File

@@ -259,7 +259,7 @@ namespace nana
for (auto pos = 0u; pos < cols; ++pos)
{
auto & el = cells[pos];
if (el.text.size() == 1 && el.text[0] == nana::char_t(0))
if (el.text.size() == 1 && el.text[0] == '\0')
continue;
text(pos, std::move(el));
}

View File

@@ -25,6 +25,8 @@ namespace nana
{
struct menu_type; //declaration
using native_string_type = ::nana::detail::native_string_type;
enum class checks
{
none,
@@ -70,7 +72,7 @@ namespace nana
event_fn_t functor;
checks style{checks::none};
paint::image image;
mutable nana::char_t hotkey{0};
mutable wchar_t hotkey{0};
};
struct menu_type
@@ -89,7 +91,7 @@ namespace nana
class renderer_interface
{
public:
typedef nana::paint::graphics & graph_reference;
using graph_reference = nana::paint::graphics &;
enum class state
{
@@ -109,7 +111,7 @@ namespace nana
virtual void background(graph_reference, window) = 0;
virtual void item(graph_reference, const nana::rectangle&, const attr&) = 0;
virtual void item_image(graph_reference, const nana::point&, unsigned image_px, const paint::image&) = 0;
virtual void item_text(graph_reference, const nana::point&, const nana::string&, unsigned text_pixels, const attr&) = 0;
virtual void item_text(graph_reference, const nana::point&, const std::string&, unsigned text_pixels, const attr&) = 0;
virtual void sub_arrow(graph_reference, const nana::point&, unsigned item_pixels, const attr&) = 0;
};
}//end namespace menu
@@ -158,7 +160,7 @@ namespace nana
bool goto_submen();///< Popup the submenu of the current item if it has a sub menu. Returns true if succeeds.
bool exit_submenu(); ///< Closes the current window of the sub menu.
std::size_t size() const; ///< Return the number of items.
int send_shortkey(nana::char_t key);
int send_shortkey(wchar_t key);
void pick();
menu& max_pixels(unsigned); ///< Sets the max width in pixels of the item.

View File

@@ -21,6 +21,8 @@ namespace nana
{
namespace menubar
{
using native_string_type = ::nana::detail::native_string_type;
class item_renderer
{
public:
@@ -33,7 +35,7 @@ namespace nana
item_renderer(window, graph_reference);
virtual void background(const point&, const ::nana::size&, state);
virtual void caption(const point&, const ::nana::string&);
virtual void caption(const point&, const native_string_type&);
private:
window handle_;
graph_reference graph_;
@@ -46,7 +48,7 @@ namespace nana
public:
trigger();
~trigger();
nana::menu* push_back(const nana::string&);
nana::menu* push_back(const std::string&);
nana::menu* at(size_t) const;
std::size_t size() const;
private:

View File

@@ -221,7 +221,7 @@ namespace nana{ namespace widgets
bool hit_select_area(nana::upoint pos) const;
bool move_select();
bool mask(char_t);
bool mask(wchar_t);
/// Returns width of text area excluding the vscroll size.
unsigned width_pixels() const;
@@ -253,8 +253,8 @@ namespace nana{ namespace widgets
bool mouse_move(bool left_button, const point& screen_pos);
bool mouse_pressed(const arg_mouse& arg);
skeletons::textbase<nana::char_t>& textbase();
const skeletons::textbase<nana::char_t>& textbase() const;
skeletons::textbase<wchar_t>& textbase();
const skeletons::textbase<wchar_t>& textbase() const;
private:
bool _m_accepts(char_type) const;
::nana::color _m_bgcolor() const;

View File

@@ -1,7 +1,7 @@
/*
* Text Token Stream
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -108,7 +108,7 @@ namespace nana{ namespace widgets{ namespace skeletons
return n;
}
private:
static bool _m_unicode_word_breakable(nana::char_t ch)
static bool _m_unicode_word_breakable(wchar_t ch)
{
return ((0x4E00 <= ch) && (ch <= 0x9FFF));
}
@@ -116,7 +116,7 @@ namespace nana{ namespace widgets{ namespace skeletons
//Read the data token
token _m_token()
{
nana::char_t ch = *iptr_;
wchar_t ch = *iptr_;
if(ch > 0xFF)
{
@@ -150,7 +150,7 @@ namespace nana{ namespace widgets{ namespace skeletons
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
{
const nana::char_t * idstr = iptr_;
auto idstr = iptr_;
do
{
ch = *(++iptr_);
@@ -172,7 +172,7 @@ namespace nana{ namespace widgets{ namespace skeletons
{
//pos keeps the current position, and it used for restring
//iptr_ when the search is failed.
const nana::char_t * pos = ++iptr_;
auto pos = ++iptr_;
_m_eat_whitespace();
if(*iptr_ == '/')
{
@@ -219,7 +219,7 @@ namespace nana{ namespace widgets{ namespace skeletons
{
_m_eat_whitespace();
nana::char_t ch = *iptr_++;
auto ch = *iptr_++;
switch(ch)
{
@@ -232,7 +232,7 @@ namespace nana{ namespace widgets{ namespace skeletons
case '"':
//Here is a string and all the meta characters will be ignored except "
{
const nana::char_t * str = iptr_;
auto str = iptr_;
while((iptr_ != endptr_) && (*iptr_ != '"'))
++iptr_;
@@ -244,7 +244,7 @@ namespace nana{ namespace widgets{ namespace skeletons
_m_eat_whitespace();
if((iptr_ < endptr_) && _m_is_idstr_element(*iptr_))
{
const nana::char_t * pbegin = iptr_;
auto pbegin = iptr_;
while((iptr_ < endptr_) && _m_is_idstr_element(*iptr_))
++iptr_;
@@ -335,7 +335,7 @@ namespace nana{ namespace widgets{ namespace skeletons
return token::eof;
}
static bool _m_is_idstr_element(nana::char_t ch)
static bool _m_is_idstr_element(wchar_t ch)
{
return (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('_' == ch) || ('0' <= ch && ch <= '9'));
}
@@ -343,9 +343,9 @@ namespace nana{ namespace widgets{ namespace skeletons
//Read the identifier.
void _m_read_idstr()
{
const nana::char_t * idstr = iptr_;
auto idstr = iptr_;
nana::char_t ch;
wchar_t ch;
do
{
ch = *(++iptr_);
@@ -360,7 +360,7 @@ namespace nana{ namespace widgets{ namespace skeletons
{
idstr_.clear();
nana::char_t ch = *iptr_;
wchar_t ch = *iptr_;
idstr_ += ch;

View File

@@ -171,12 +171,12 @@ namespace nana
textbox& multi_lines(bool);
bool editable() const;
textbox& editable(bool);
void set_accept(std::function<bool(nana::char_t)>);
void set_accept(std::function<bool(wchar_t)>);
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);
textbox& mask(wchar_t);
/// Returns true if some text is selected.
bool selected() const;

View File

@@ -93,7 +93,7 @@ namespace nana
void umake_event(event_handle eh) const; ///< Deletes an event callback by a handle.
widget& register_shortkey(char_t); ///< Registers a shortkey. To remove a registered key, pass 0.
widget& register_shortkey(wchar_t); ///< Registers a shortkey. To remove a registered key, pass 0.
widget& take_active(bool activated, window take_if_not_activated);
widget& tooltip(const ::std::string&);

View File

@@ -32,9 +32,9 @@ namespace detail
void blend(drawable_type dw, const nana::rectangle& r, pixel_color_t, double fade_rate);
nana::size raw_text_extent_size(drawable_type, const nana::char_t*, std::size_t len);
nana::size text_extent_size(drawable_type, const nana::char_t*, std::size_t len);
void draw_string(drawable_type, const nana::point&, const nana::char_t *, std::size_t len);
nana::size raw_text_extent_size(drawable_type, const wchar_t*, std::size_t len);
nana::size text_extent_size(drawable_type, const wchar_t*, std::size_t len);
void draw_string(drawable_type, const nana::point&, const wchar_t *, std::size_t len);
}//end namespace detail
}//end namespace paint
}//end namespace nana

View File

@@ -144,7 +144,7 @@ namespace nana
::nana::color palette(bool for_text) const;
graphics& palette(bool for_text, const ::nana::color&);
unsigned bidi_string(const nana::point&, const char_t *, std::size_t len);
unsigned bidi_string(const nana::point&, const wchar_t *, std::size_t len);
unsigned bidi_string(const point& pos, const char*, std::size_t len);
void blend(const ::nana::rectangle& r, const ::nana::color&, double fade_rate);

View File

@@ -13,11 +13,11 @@ namespace nana
text_renderer(graph_reference graph, align = align::left);
nana::size extent_size(int x, int y, const nana::char_t*, std::size_t len, unsigned restricted_pixels) const;
nana::size extent_size(int x, int y, const wchar_t*, std::size_t len, unsigned restricted_pixels) const;
void render(const point&, const char_t*, std::size_t len);
void render(const point&, const char_t*, std::size_t len, unsigned restricted_pixels, bool omitted);
void render(const point&, const char_t*, std::size_t len, unsigned restricted_pixels);
void render(const point&, const wchar_t*, std::size_t len);
void render(const point&, const wchar_t*, std::size_t len, unsigned restricted_pixels, bool omitted);
void render(const point&, const wchar_t*, std::size_t len, unsigned restricted_pixels);
private:
graph_reference graph_;
align text_align_;

View File

@@ -38,7 +38,7 @@ namespace system
bool get_async_mouse_state(int button);
//open an url through a default browser
void open_url(const nana::string& url);
void open_url(const std::string& url);
}//end namespace system
}//end namespace nana