refactor functions

This commit is contained in:
Jinhao
2017-05-31 22:36:56 +08:00
parent 5746fc33f6
commit a87703d418
9 changed files with 121 additions and 143 deletions

View File

@@ -131,7 +131,7 @@ namespace nana
if (((0 == thread_id) || (wd->thread_id == thread_id)) && (wd->root != root))
{
root = wd->root;
if (roots.cend() == std::find(roots.cbegin(), roots.cend(), root))
if (roots.end() == std::find(roots.begin(), roots.end(), root))
roots.emplace_back(root);
}
}

View File

@@ -1397,14 +1397,14 @@ namespace detail
{
auto & tabs = wd->root_widget->other.attribute.root->tabstop;
auto end = tabs.cend();
auto end = tabs.end();
if (forward)
{
if (detail::tab_type::none == wd->flags.tab)
return (tabs.front());
else if (detail::tab_type::tabstop & wd->flags.tab)
{
auto i = std::find(tabs.cbegin(), end, wd);
auto i = std::find(tabs.begin(), end, wd);
if (i != end)
{
++i;
@@ -1417,9 +1417,9 @@ namespace detail
}
else if (tabs.size() > 1) //at least 2 elments in tabs are required when moving backward.
{
auto i = std::find(tabs.cbegin(), end, wd);
auto i = std::find(tabs.begin(), end, wd);
if (i != end)
return (tabs.cbegin() == i ? tabs.back() : *(i - 1));
return (tabs.begin() == i ? tabs.back() : *(i - 1));
}
return nullptr;
}
@@ -1549,7 +1549,7 @@ namespace detail
for (auto child : wd->children)
{
auto child_keys = shortkeys(child, true);
std::copy(child_keys.cbegin(), child_keys.cend(), std::back_inserter(result));
std::copy(child_keys.begin(), child_keys.end(), std::back_inserter(result));
}
}
}
@@ -1716,7 +1716,7 @@ namespace detail
if (pa_children.size() > 1)
{
for (auto i = pa_children.cbegin(), end = pa_children.cend(); i != end; ++i)
for (auto i = pa_children.begin(), end = pa_children.end(); i != end; ++i)
{
if (((*i)->index) > (wd->index))
{

View File

@@ -519,9 +519,7 @@ namespace nana
void _m_draw_block(graph_reference graph, const std::wstring& s, dstream::linecontainer::iterator block_start, render_status& rs)
{
nana::unicode_bidi bidi;
std::vector<nana::unicode_bidi::entity> reordered;
bidi.linestr(s.data(), s.length(), reordered);
auto const reordered = unicode_reorder(s.data(), s.length());
pixel_tag px = rs.pixels[rs.index];

View File

@@ -332,7 +332,8 @@ namespace nana
unsigned ranged_px = 0;
unsigned ranged_count = 0;
for (auto & col : cont_)
auto const & const_cont = cont_;
for (auto & col : const_cont)
{
if (col.visible_state)
{
@@ -486,27 +487,6 @@ namespace nana
return{ left, 0 };
}
/*
/// Returns the left point position and width(in variable *pixels) of column originaly at position pos.
int position(size_type pos, unsigned * pixels) const
{
int left = 0;
for (auto & m : cont_)
{
if (m.index == pos)
{
if (pixels)
*pixels = m.width_px;
break;
}
if (m.visible_state)
left += m.width_px;
}
return left;
}
*/
/// return the original index of the visible col currently before(in front of) or after the col originaly at index "index"
size_type next(size_type index) const noexcept
{
@@ -548,11 +528,15 @@ namespace nana
if ((from == to) || (from >= cont_.size()) || (to >= cont_.size()))
return;
#ifdef _MSC_VER
for (auto i = cont_.cbegin(); i != cont_.cend(); ++i)
#else
for (auto i = cont_.begin(); i != cont_.end(); ++i)
#endif
{
if (from == i->index)
{
auto col_from = std::move(*i);
auto col_from = *i;
cont_.erase(i);
//A workaround for old libstdc++, that some operations of vector
@@ -781,19 +765,6 @@ namespace nana
std::string to_string(const export_options& exp_opt) const;
std::vector<inline_pane*> get_inline_pane(const index_pair& item_pos)
{
std::vector<inline_pane*> panes;
for (auto p : active_panes_)
{
if (p && (p->item_pos == item_pos))
{
panes.emplace_back(p);
}
}
return panes;
}
void emit_cs(const index_pair& pos, bool for_selection)
{
item_proxy i(ess_, pos);
@@ -806,13 +777,16 @@ namespace nana
else
events.checked.emit(arg, wd_ptr()->handle());
auto panes = get_inline_pane(pos);
for (auto p : panes)
//notify the inline pane. An item may have multiple panes, each pane is for a column.
for (auto p : active_panes_)
{
if(for_selection)
p->inline_ptr->notify_status(inline_widget_status::selecting, i.selected());
else
p->inline_ptr->notify_status(inline_widget_status::checking, i.checked());
if (p && (p->item_pos == pos))
{
if (for_selection)
p->inline_ptr->notify_status(inline_widget_status::selecting, i.selected());
else
p->inline_ptr->notify_status(inline_widget_status::checking, i.checked());
}
}
}

View File

@@ -407,11 +407,11 @@ namespace nana{ namespace widgets
std::shared_ptr<colored_area_type> find(std::size_t pos) const
{
for (auto i = colored_areas_.cbegin(); i != colored_areas_.cend(); ++i)
for (auto & sp : colored_areas_)
{
if (i->get()->begin <= pos && pos < i->get()->begin + i->get()->count)
return *i;
else if (i->get()->begin > pos)
if (sp->begin <= pos && pos < sp->begin + sp->count)
return sp;
else if (sp->begin > pos)
break;
}
return{};
@@ -623,7 +623,9 @@ namespace nana{ namespace widgets
//textbase is implement by using deque, and the linemtr holds the text pointers
//If the textbase is changed, it will check the text pointers.
std::size_t line = 0;
for (auto & sct : this->sections_)
auto const & const_sections = sections_;
for (auto & sct : const_sections)
{
auto const& text = editor_.textbase().getline(line);
if (sct.begin < text.c_str() || (text.c_str() + text.size() < sct.begin))
@@ -646,7 +648,9 @@ namespace nana{ namespace widgets
//textbase is implement by using deque, and the linemtr holds the text pointers
//If the textbase is changed, it will check the text pointers.
std::size_t line = 0;
for (auto & sct : this->sections_)
auto const & const_sections = sections_;
for (auto & sct : const_sections)
{
if (line < pos || (pos + line_size) <= line)
{
@@ -664,8 +668,8 @@ namespace nana{ namespace widgets
auto const & text = editor_.textbase().getline(pos);
auto& txt_section = this->sections_[pos];
txt_section.begin = text.c_str();
txt_section.end = text.c_str() + text.size();
txt_section.pixels = editor_._m_text_extent_size(text.c_str(), text.size()).width;
txt_section.end = txt_section.begin + text.size();
txt_section.pixels = editor_._m_text_extent_size(txt_section.begin, text.size()).width;
}
void pre_calc_lines(unsigned) override
@@ -756,7 +760,9 @@ namespace nana{ namespace widgets
//textbase is implement by using deque, and the linemtr holds the text pointers
//If the textbase is changed, it will check the text pointers.
std::size_t line = 0;
for (auto & mtr : linemtr_)
auto const & const_linemtr = linemtr_;
for (auto & mtr : const_linemtr)
{
if (line < pos || (pos + lines) <= line)
{
@@ -2031,11 +2037,9 @@ namespace nana{ namespace widgets
return;
auto undo_ptr = std::unique_ptr<undo_input_text>(new undo_input_text(*this, std::wstring(1, '\n')));
bool need_refresh = (select_.a != select_.b);
undo_ptr->set_selected_text();
if(need_refresh)
points_.caret = _m_erase_select();
points_.caret = _m_erase_select();
undo_ptr->set_caret_pos();
@@ -2067,12 +2071,7 @@ namespace nana{ namespace widgets
points_.caret.x = 0;
auto origin = impl_->cview->origin();
if (origin.x || (points_.caret.y < textbase.lines()) || textbase.getline(points_.caret.y).size())
{
origin.x = -origin.x;
impl_->cview->move_origin(origin);
need_refresh = true;
}
origin.x = 0;
if (impl_->indent.enabled)
{
@@ -2090,13 +2089,13 @@ namespace nana{ namespace widgets
put(text);
}
}
else
_m_reset_content_size();
impl_->cview->move_origin(origin - impl_->cview->origin());
auto origin_moved = impl_->cview->move_origin(origin - impl_->cview->origin());
if (this->_m_adjust_view() || need_refresh)
if (this->_m_adjust_view() || origin_moved)
impl_->cview->sync(true);
_m_reset_content_size();
}
void text_editor::del()
@@ -2630,8 +2629,7 @@ namespace nana{ namespace widgets
text_ptr = mask_str.c_str();
}
std::vector<unicode_bidi::entity> reordered;
unicode_bidi{}.linestr(text_ptr, text_size, reordered);
auto const reordered = unicode_reorder(text_ptr, text_size);
nana::upoint res(static_cast<unsigned>(real_str.begin - sections.front().begin), static_cast<unsigned>(row.first));
@@ -3333,8 +3331,7 @@ namespace nana{ namespace widgets
const auto focused = API::is_focus_ready(window_);
std::vector<unicode_bidi::entity> reordered;
unicode_bidi{}.linestr(text_ptr, text_len, reordered);
auto const reordered = unicode_reorder(text_ptr, text_len);
//Parse highlight keywords
keyword_parser parser;
@@ -3564,9 +3561,8 @@ namespace nana{ namespace widgets
if (pos > lnstr.size())
return 0;
std::vector<unicode_bidi::entity> reordered;
unicode_bidi{}.linestr(lnstr.c_str(), lnstr.size(), reordered);
auto const reordered = unicode_reorder(lnstr.c_str(), lnstr.size());
auto target = lnstr.c_str() + pos;
unsigned text_w = 0;