From 5d5a808b2d4de634ca0a9c50f2b9a3dc1250822f Mon Sep 17 00:00:00 2001 From: Jinhao Date: Wed, 13 Jul 2016 08:00:59 +0800 Subject: [PATCH] remove overloading assignment operator of rectangle --- include/nana/basic_types.hpp | 3 - source/basic_types.cpp | 14 --- source/gui/detail/basic_window.cpp | 2 +- source/gui/layout_utility.cpp | 2 +- source/gui/place.cpp | 6 +- source/gui/programming_interface.cpp | 2 +- source/gui/widgets/listbox.cpp | 98 ++++++++++++-------- source/gui/widgets/picture.cpp | 2 +- source/gui/widgets/skeletons/text_editor.cpp | 2 +- source/gui/widgets/treebox.cpp | 4 +- 10 files changed, 71 insertions(+), 64 deletions(-) diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index adbf55da..6ddb6912 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -449,9 +449,6 @@ namespace nana bool operator==(const rectangle& rhs) const; bool operator!=(const rectangle& rhs) const; - rectangle& operator=(const point&); - rectangle& operator=(const size&); - point position() const noexcept; rectangle& position(const point&) noexcept; diff --git a/source/basic_types.cpp b/source/basic_types.cpp index b5f7716b..6a40ee59 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -607,20 +607,6 @@ namespace nana return (width != rhs.width) || (height != rhs.height) || (x != rhs.x) || (y != rhs.y); } - rectangle & rectangle::operator=(const point& pos) - { - x = pos.x; - y = pos.y; - return *this; - } - - rectangle & rectangle::operator=(const size & sz) - { - width = sz.width; - height = sz.height; - return *this; - } - point rectangle::position() const noexcept { return{ x, y }; diff --git a/source/gui/detail/basic_window.cpp b/source/gui/detail/basic_window.cpp index faf0b553..525f5e57 100644 --- a/source/gui/detail/basic_window.cpp +++ b/source/gui/detail/basic_window.cpp @@ -61,7 +61,7 @@ namespace nana if (0 == effect_range_.width || 0 == effect_range_.height) { rect.x = rect.y = 0; - rect = owner_->dimension; + rect.dimension(owner_->dimension); } else { diff --git a/source/gui/layout_utility.cpp b/source/gui/layout_utility.cpp index 3afc6e62..4daade4a 100644 --- a/source/gui/layout_utility.cpp +++ b/source/gui/layout_utility.cpp @@ -56,7 +56,7 @@ namespace nana if (overlap(ir, valid_r, op_ir) == false) return false; - valid_r = valid_dst_area; + valid_r.dimension(valid_dst_area); rectangle good_dr; if (overlap(dr, valid_r, good_dr) == false) return false; diff --git a/source/gui/place.cpp b/source/gui/place.cpp index 4b9e135b..bfa0e658 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -1684,7 +1684,7 @@ namespace nana graph.blend(r, clr, 0.5); r.x = r.y = 0; - r = graph.size(); + r.dimension(graph.size()); r.width = border_px; graph.blend(r, clr, 0.5); r.x = right - border_px; @@ -2099,7 +2099,7 @@ namespace nana { if (root_division && window_handle) { - root_division->field_area = API::window_size(window_handle); + root_division->field_area.dimension(API::window_size(window_handle)); if (root_division->field_area.empty()) return; @@ -2590,7 +2590,7 @@ namespace nana { if (impl_->root_division) { - impl_->root_division->field_area = ::nana::size(arg.width, arg.height); + impl_->root_division->field_area.dimension({ arg.width, arg.height }); impl_->root_division->collocate(arg.window_handle); } }); diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 4485b260..787a2183 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -474,7 +474,7 @@ namespace API nana::point pos{ r.x, r.y }; calc_window_point(wd, pos); - r = pos; + r.position(pos); return r; } diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 21f288a7..a9b510b9 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -565,7 +565,7 @@ namespace nana { using container = std::vector; - container cells; + std::unique_ptr cells; nana::color bgcolor; nana::color fgcolor; paint::image img; @@ -585,7 +585,7 @@ namespace nana } item_data(const item_data& r) - : cells(r.cells), + : cells(r.cells ? std::make_unique(*r.cells) : nullptr), bgcolor(r.bgcolor), fgcolor(r.fgcolor), img(r.img), @@ -594,30 +594,34 @@ namespace nana {} item_data(container&& cont) - : cells(std::move(cont)) + : cells(std::make_unique(std::move(cont))) { flags.selected = flags.checked = false; } item_data(std::string&& s) + : cells(std::make_unique()) { flags.selected = flags.checked = false; - cells.emplace_back(std::move(s)); + cells->emplace_back(std::move(s)); } - item_data(std::string&& s, const nana::color& bg, const nana::color& fg) - : bgcolor(bg), - fgcolor(fg) + item_data(std::string&& s, const nana::color& bg, const nana::color& fg): + cells(std::make_unique()), + bgcolor(bg), + fgcolor(fg) { flags.selected = flags.checked = false; - cells.emplace_back(std::move(s)); + cells->emplace_back(std::move(s)); } item_data& operator=(const item_data& r) { if (this != &r) { - cells = r.cells; + if (r.cells) + cells = std::make_unique(*r.cells); + flags = r.flags; anyobj.reset(r.anyobj ? new nana::any(*r.anyobj) : nullptr); bgcolor = r.bgcolor; @@ -644,7 +648,7 @@ namespace nana if (model_cells) item_str += model_cells->operator[](col).text; else - item_str += cells[col].text; + item_str += (*cells)[col].text; } return item_str; @@ -790,20 +794,20 @@ namespace nana auto & mx = cat.items[x]; auto & my = cat.items[y]; - if (mx.cells.size() <= sorted_index_ || my.cells.size() <= sorted_index_) + if (mx.cells->size() <= sorted_index_ || my.cells->size() <= sorted_index_) { std::string a; - if (mx.cells.size() > sorted_index_) - a = mx.cells[sorted_index_].text; + if (mx.cells->size() > sorted_index_) + a = (*mx.cells)[sorted_index_].text; std::string b; - if (my.cells.size() > sorted_index_) - b = my.cells[sorted_index_].text; + if (my.cells->size() > sorted_index_) + b = (*my.cells)[sorted_index_].text; return weak_ordering_comp(a, mx.anyobj.get(), b, my.anyobj.get(), sorted_reverse_); } - return weak_ordering_comp(mx.cells[sorted_index_].text, mx.anyobj.get(), my.cells[sorted_index_].text, my.anyobj.get(), sorted_reverse_); + return weak_ordering_comp((*mx.cells)[sorted_index_].text, mx.anyobj.get(), (*my.cells)[sorted_index_].text, my.anyobj.get(), sorted_reverse_); }); } } @@ -843,21 +847,21 @@ namespace nana auto & mx = cat.items[x]; auto & my = cat.items[y]; - if (mx.cells.size() <= sorted_index_ || my.cells.size() <= sorted_index_) + if (mx.cells->size() <= sorted_index_ || my.cells->size() <= sorted_index_) { std::string a; - if (mx.cells.size() > sorted_index_) - a = mx.cells[sorted_index_].text; + if (mx.cells->size() > sorted_index_) + a = (*mx.cells)[sorted_index_].text; std::string b; - if (my.cells.size() > sorted_index_) - b = my.cells[sorted_index_].text; + if (my.cells->size() > sorted_index_) + b = (*my.cells)[sorted_index_].text; return (sorted_reverse_ ? a > b : a < b); } - auto & a = mx.cells[sorted_index_].text; - auto & b = my.cells[sorted_index_].text; + auto & a = (*mx.cells)[sorted_index_].text; + auto & b = (*my.cells)[sorted_index_].text; return (sorted_reverse_ ? a > b : a < b); }); } @@ -1010,7 +1014,7 @@ namespace nana catobj.items.emplace_back(std::move(text)); } - catobj.items.back().cells.emplace_back(std::move(text)); + catobj.items.back().cells->emplace_back(std::move(text)); } /// convert from display order to absolute (find the real item in that display pos) but without check from current active sorting, in fact using just the last sorting !!! @@ -1268,7 +1272,7 @@ namespace nana if (cat->model_ptr) throw std::runtime_error("nana::listbox disallow to get item cells, because there are model cells"); - return cat->items.at(pos).cells; + return *(cat->items.at(pos).cells); } std::vector get_model_cells(category_t* cat, std::size_t pos) const @@ -1295,7 +1299,7 @@ namespace nana model_cells = cat->model_ptr->container()->to_cells(pos); } - auto & cells = (cat->model_ptr ? model_cells : cat->items[pos].cells); + auto & cells = (cat->model_ptr ? model_cells : *(cat->items[pos].cells)); if (col < cells.size()) { @@ -1328,7 +1332,7 @@ namespace nana model_cells = cat->model_ptr->container()->to_cells(pos); } - auto & cells = (cat->model_ptr ? model_cells : cat->items[pos].cells); + auto & cells = (cat->model_ptr ? model_cells : *(cat->items[pos].cells)); if (col < cells.size()) { @@ -1934,6 +1938,7 @@ namespace nana return (display_pos.item < catobj.sorted.size() ? catobj.sorted[display_pos.item] : npos); } + index_pair absolute_pair(const index_pair& display_pos) const { //Returns an empty pos if item pos npos @@ -2499,7 +2504,7 @@ namespace nana { if (lister.wd_ptr()->borderless()) { - r = graph->size(); + r.dimension(graph->size()); r.height = scheme_ptr->header_height; return !r.empty(); } @@ -2870,14 +2875,30 @@ namespace nana unsigned max_px = 0; for (auto & cat : categories_) { - for (auto & m : cat.items) + if (cat.model_ptr) { - if (pos >= m.cells.size()) - continue; + for (std::size_t i = 0; i < cat.items.size(); ++i) + { + auto model_cells = cat.model_ptr->container()->to_cells(i); + if (pos >= model_cells.size()) + continue; - auto content_px = ess_->graph->text_extent_size(m.cells[pos].text).width; - if (content_px > max_px) - max_px = content_px; + auto content_px = ess_->graph->text_extent_size(model_cells[pos].text).width; + if (content_px > max_px) + max_px = content_px; + } + } + else + { + for (auto & m : cat.items) + { + if (pos >= m.cells->size()) + continue; + + auto content_px = ess_->graph->text_extent_size((*m.cells)[pos].text).width; + if (content_px > max_px) + max_px = content_px; + } } } return max_px; @@ -2965,7 +2986,7 @@ namespace nana ess_->lister.throw_if_immutable_model(pos); auto model_cells = ess_->lister.at_model_abs(pos); - auto & cells = ess_->lister.have_model(pos) ? model_cells : ess_->lister.at_abs(pos).cells; + auto & cells = ess_->lister.have_model(pos) ? model_cells : (*ess_->lister.at_abs(pos).cells); if (cells.size() <= column_pos_) cells.resize(column_pos_ + 1); @@ -3696,7 +3717,7 @@ namespace nana model_cells = cat.model_ptr->container()->to_cells(item_pos.item); } - auto & cells = (cat.model_ptr ? model_cells : item.cells); + auto & cells = (cat.model_ptr ? model_cells : *item.cells); if (item.flags.selected) // fetch the "def" colors bgcolor = essence_->scheme_ptr->item_selected; @@ -5050,7 +5071,10 @@ namespace nana cat_->sorted.clear(); cat_->items.resize(cat_->model_ptr->container()->size()); - for (std::size_t pos = 0; pos < cat_->items.size(); ++pos) + + const auto item_size = cat_->items.size(); + cat_->sorted.reserve(item_size + 100); + for (std::size_t pos = 0; pos != item_size; ++pos) cat_->sorted.push_back(pos); ess_->lister.sort(); diff --git a/source/gui/widgets/picture.cpp b/source/gui/widgets/picture.cpp index 9733e120..bf739693 100644 --- a/source/gui/widgets/picture.cpp +++ b/source/gui/widgets/picture.cpp @@ -76,7 +76,7 @@ namespace nana { auto valid_area = backimg.valid_area; if (valid_area.empty()) - valid_area = backimg.image.size(); + valid_area.dimension(backimg.image.size()); if (backimg.stretchable) { diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 94e0f3f8..09a1c556 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1280,7 +1280,7 @@ namespace nana{ namespace widgets graph_(graph), scheme_(schm), keywords_(new keywords) { - text_area_.area = graph.size(); + text_area_.area.dimension(graph.size()); text_area_.captured = false; text_area_.tab_space = 4; text_area_.scroll_pixels = 16; diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index e319b54f..b0895943 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -1274,8 +1274,8 @@ namespace nana attr.area.x += (attr.area.width - fit_size.width) / 2; attr.area.y += (attr.area.height - fit_size.height) / 2; - attr.area = fit_size; - img->stretch(::nana::rectangle{ size }, graph, attr.area); + attr.area.dimension(fit_size); + img->stretch(rectangle{ size }, graph, attr.area); } else img->paste(graph, point{ attr.area.x + static_cast(attr.area.width - size.width) / 2, attr.area.y + static_cast(attr.area.height - size.height) / 2 });