code review

This commit is contained in:
Jinhao
2015-10-22 00:02:27 +08:00
parent 5590dd293b
commit fb3b1d51d4
7 changed files with 180 additions and 195 deletions

View File

@@ -208,7 +208,7 @@ namespace nana{ namespace widgets
/// Sets caret position through text coordinate.
void move_caret(const upoint&);
void move_caret_end();
void reset_caret_height() const;
void reset_caret_pixels() const;
void reset_caret();
void show_caret(bool isshow);
@@ -216,8 +216,10 @@ namespace nana{ namespace widgets
bool select(bool);
/// Sets the end position of a selected string.
void set_end_caret();
bool hit_text_area(const point&) const;
bool hit_select_area(nana::upoint pos) const;
bool move_select();
bool mask(char_t);
@@ -245,8 +247,8 @@ namespace nana{ namespace widgets
void move_ns(bool to_north); //Moves up and down
void move_left();
void move_right();
upoint mouse_caret(const point& screen_pos);
upoint caret() const;
const upoint& mouse_caret(const point& screen_pos);
const upoint& caret() const;
point caret_screen_pos() const;
bool scroll(bool upwards, bool vertical);
bool mouse_enter(bool);
@@ -256,8 +258,6 @@ namespace nana{ namespace widgets
skeletons::textbase<nana::char_t>& textbase();
const skeletons::textbase<nana::char_t>& textbase() const;
std::vector<unsigned> get_lines() const;
private:
bool _m_accepts(char_type) const;
::nana::color _m_bgcolor() const;
@@ -283,10 +283,8 @@ namespace nana{ namespace widgets
int _m_text_top_base() const;
/// Returns the right point of text area.
int _m_endx() const;
/// Returns the bottom point of text area.
int _m_endy() const;
/// Returns the right/bottom point of text area.
int _m_end_pos(bool right) const;
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const ::nana::char_t*, std::size_t len) const;
//_m_draw_string
@@ -302,7 +300,6 @@ namespace nana{ namespace widgets
unsigned _m_char_by_pixels(const nana::char_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl);
unsigned _m_pixels_by_char(const nana::string&, std::size_t pos) const;
static bool _m_is_right_text(const unicode_bidi::entity&);
void _handle_move_key(const arg_keyboard& arg);
private:

View File

@@ -249,60 +249,58 @@ namespace skeletons
return true;
}
void store(nana::string fs) const
void store(nana::string fs, bool is_unicode, ::nana::unicode encoding) const
{
std::string fs_mbs = nana::charset(fs);
std::ofstream ofs(fs_mbs.data(), std::ios::binary);
if(ofs && text_cont_.size())
{
if(text_cont_.size() > 1)
std::string last_mbs;
if (is_unicode)
{
for(auto i = text_cont_.cbegin(), end = text_cont_.cend() - 1; i != end; ++i)
const char * le_boms[] = { "\xEF\xBB\xBF", "\xFF\xFE", "\xFF\xFE\x0\x0" }; //BOM for little-endian
int bytes = 0;
switch (encoding)
{
std::string mbs = nana::charset(*i);
ofs.write(mbs.c_str(), mbs.size());
ofs.write("\r\n", 2);
case nana::unicode::utf8:
bytes = 3; break;
case nana::unicode::utf16:
bytes = 2; break;
case nana::unicode::utf32:
bytes = 4; break;
}
}
std::string mbs = nana::charset(text_cont_.back());
ofs.write(mbs.c_str(), mbs.size());
_m_saved(std::move(fs));
}
}
void store(nana::string fs, nana::unicode encoding) const
{
std::string fs_mbs = nana::charset(fs);
std::ofstream ofs(fs_mbs.data(), std::ios::binary);
if(ofs && text_cont_.size())
{
const char * le_boms[] = {"\xEF\xBB\xBF", "\xFF\xFE", "\xFF\xFE\x0\x0"}; //BOM for little-endian
int bytes = 0;
switch(encoding)
{
case nana::unicode::utf8:
bytes = 3; break;
case nana::unicode::utf16:
bytes = 2; break;
case nana::unicode::utf32:
bytes = 4; break;
}
if (bytes)
ofs.write(le_boms[static_cast<int>(encoding)], bytes);
if(bytes)
ofs.write(le_boms[static_cast<int>(encoding)], bytes);
if(text_cont_.size() > 1)
{
std::string mbs;
for(auto i = text_cont_.cbegin(), end = text_cont_.cend() - 1; i != end; ++i)
if (text_cont_.size() > 1)
{
mbs = nana::charset(*i).to_bytes(encoding);
mbs += "\r\n";
ofs.write(mbs.c_str(), static_cast<std::streamsize>(mbs.size()));
std::string mbs;
for (auto i = text_cont_.cbegin(), end = text_cont_.cend() - 1; i != end; ++i)
{
std::string(nana::charset(*i).to_bytes(encoding)).swap(mbs);
mbs += "\r\n";
ofs.write(mbs.c_str(), static_cast<std::streamsize>(mbs.size()));
}
}
last_mbs = nana::charset(text_cont_.back()).to_bytes(encoding);
}
std::string mbs = nana::charset(text_cont_.back()).to_bytes(encoding);
ofs.write(mbs.c_str(), static_cast<std::streamsize>(mbs.size()));
else
{
if (text_cont_.size() > 1)
{
for (auto i = text_cont_.cbegin(), end = text_cont_.cend() - 1; i != end; ++i)
{
std::string mbs = nana::charset(*i);
ofs.write(mbs.c_str(), mbs.size());
ofs.write("\r\n", 2);
}
}
last_mbs = nana::charset(text_cont_.back());
}
ofs.write(last_mbs.c_str(), static_cast<std::streamsize>(last_mbs.size()));
_m_saved(std::move(fs));
}
}