diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 3765c3db..35659972 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -100,9 +100,6 @@ namespace nana void throw_not_utf8(const char*, unsigned len); void throw_not_utf8(const char*); - std::wstring utf8_cast(const std::string&); - std::string utf8_cast(const std::wstring&); - const std::string& to_utf8(const std::string&); std::string to_utf8(const std::wstring&); diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index 4f4423a1..dc86d1e0 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -332,8 +332,6 @@ namespace filesystem //uintmax_t remove_all(const path& p); //uintmax_t remove_all(const path& p, error_code& ec) noexcept; - //bool rmdir(const path& p, bool fails_if_not_empty); //deprecated - template std::basic_string parent_path(const std::basic_string& path) { diff --git a/include/nana/gui/widgets/checkbox.hpp b/include/nana/gui/widgets/checkbox.hpp index 4f89b422..8d458be3 100644 --- a/include/nana/gui/widgets/checkbox.hpp +++ b/include/nana/gui/widgets/checkbox.hpp @@ -56,14 +56,8 @@ namespace drawerbase void mouse_up(graph_reference, const arg_mouse&) override; public: implement * impl() const; - private: - void _m_draw_background(graph_reference); - void _m_draw_checkbox(graph_reference, unsigned first_line_height); - void _m_draw_title(graph_reference); private: static const int interval = 4; - widget* widget_; - std::unique_ptr imptr_; implement * impl_; }; }//end namespace checkbox diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 4aa7cfb7..d8e94b0d 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -158,7 +158,7 @@ namespace nana iresolver& operator>>(double&); iresolver& operator>>(long double&); - iresolver& operator>>(std::string& utf8_cast); + iresolver& operator>>(std::string& text_utf8); iresolver& operator>>(std::wstring&); iresolver& operator>>(cell&); iresolver& operator>>(std::nullptr_t); diff --git a/source/deploy.cpp b/source/deploy.cpp index 2594de28..3592a3bf 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -487,16 +487,6 @@ namespace nana } - 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); - } - const std::string& to_utf8(const std::string& str) { return str; diff --git a/source/detail/platform_spec_windows.cpp b/source/detail/platform_spec_windows.cpp index de46dbea..88317ede 100644 --- a/source/detail/platform_spec_windows.cpp +++ b/source/detail/platform_spec_windows.cpp @@ -207,7 +207,7 @@ namespace detail #endif #endif ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof metrics, &metrics, 0); - def_font_ptr_ = make_native_font(utf8_cast(metrics.lfMessageFont.lfFaceName).c_str(), font_size_to_height(9), 400, false, false, false); + def_font_ptr_ = make_native_font(to_utf8(metrics.lfMessageFont.lfFaceName).c_str(), font_size_to_height(9), 400, false, false, false); } const platform_spec::font_ptr_t& platform_spec::default_native_font() const @@ -244,7 +244,7 @@ namespace detail memset(&logfont, 0, sizeof logfont); if (name && *name) - std::wcscpy(logfont.lfFaceName, utf8_cast(name).c_str()); + std::wcscpy(logfont.lfFaceName, to_wstring(name).c_str()); else std::wcscpy(logfont.lfFaceName, def_font_ptr_->name.c_str()); diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index af47ab80..59c848cf 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -282,20 +282,12 @@ namespace nana { namespace experimental { void path::_m_assign(const std::string& source_utf8) { -#if defined(NANA_WINDOWS) - pathstr_ = utf8_cast(source_utf8); -#else - pathstr_ = source_utf8; -#endif + pathstr_ = to_nstring(source_utf8); } void path::_m_assign(const std::wstring& source) { -#if defined(NANA_WINDOWS) - pathstr_ = source; -#else - pathstr_ = utf8_cast(source); -#endif + pathstr_ = to_nstring(source); } //end class path diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index 6dba26c5..0b85b644 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -1191,7 +1191,7 @@ namespace detail ::DragQueryFile(drop, i, varbuf.get(), reqlen); - dropfiles.files.emplace_back(utf8_cast(varbuf.get())); + dropfiles.files.emplace_back(to_utf8(varbuf.get())); } while(msgwnd && (msgwnd->flags.dropable == false)) diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index a0985165..f89c400a 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -912,7 +912,7 @@ namespace nana ::GetCurrentDirectory(len, &(path[0])); path.resize(len); - impl_->path = utf8_cast(path); + impl_->path = to_utf8(path); } #endif } @@ -1002,9 +1002,9 @@ namespace nana { for(auto & f : impl_->filters) { - filter_holder += utf8_cast(f.des); + filter_holder += to_wstring(f.des); filter_holder += static_cast('\0'); - std::wstring fs = utf8_cast(f.type); + std::wstring fs = to_wstring(f.type); std::size_t pos = 0; while(true) { @@ -1036,8 +1036,8 @@ namespace nana else filter = L"All Files\0*.*\0"; - auto wtitle = utf8_cast(impl_->title); - auto wpath = utf8_cast(impl_->path); + auto wtitle = to_wstring(impl_->title); + auto wpath = to_wstring(impl_->path); ofn.lpstrFilter = filter; ofn.lpstrTitle = (wtitle.empty() ? nullptr : wtitle.c_str()); ofn.nFilterIndex = 0; @@ -1053,7 +1053,7 @@ namespace nana return false; wfile.resize(std::wcslen(wfile.data())); - impl_->file = utf8_cast(wfile); + impl_->file = to_utf8(wfile); #elif defined(NANA_POSIX) filebox_implement fb(impl_->owner, impl_->open_or_save, impl_->title); diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index 4cd36b0f..dd20cf6e 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -435,7 +435,7 @@ namespace nana default: break; } - auto bt = ::MessageBoxW(reinterpret_cast(API::root(wd_)), utf8_cast(sstream_.str()).c_str(), utf8_cast(title_).c_str(), type); + auto bt = ::MessageBoxW(reinterpret_cast(API::root(wd_)), to_wstring(sstream_.str()).c_str(), to_wstring(title_).c_str(), type); switch(bt) { @@ -835,7 +835,7 @@ namespace nana void inputbox::text::tip_string(std::wstring tip) { - impl_->tip = utf8_cast(tip); + impl_->tip = to_utf8(tip); } void inputbox::text::tip_string(std::string tip_utf8) diff --git a/source/gui/place.cpp b/source/gui/place.cpp index 0b96dbf1..d6adb5d0 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -1,7 +1,7 @@ /* * An Implementation of Place for Layout * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/source/gui/place_parts.hpp b/source/gui/place_parts.hpp index 5daba048..25708b93 100644 --- a/source/gui/place_parts.hpp +++ b/source/gui/place_parts.hpp @@ -83,7 +83,7 @@ namespace nana graph.rectangle(true, static_cast(0x83EB)); //draw caption - auto text = utf8_cast(API::window_caption(window_handle_)); + auto text = to_wstring(API::window_caption(window_handle_)); text_rd_->render({ 3, 1 }, text.data(), text.size(), graph.size().width - 20, true); //draw x button diff --git a/source/gui/widgets/checkbox.cpp b/source/gui/widgets/checkbox.cpp index e0e0aa75..31ef7146 100644 --- a/source/gui/widgets/checkbox.cpp +++ b/source/gui/widgets/checkbox.cpp @@ -17,39 +17,68 @@ namespace nana{ namespace drawerbase { -namespace checkbox -{ - typedef element::crook_interface::state crook_state; - - struct drawer::implement + namespace checkbox { - bool react; - bool radio; - facade crook; - }; + typedef element::crook_interface::state crook_state; + + struct drawer::implement + { + widget * widget_ptr; + bool react; + bool radio; + facade crook; + }; + + //class drawer drawer::drawer() - : widget_(nullptr), - imptr_(new drawer::implement), - impl_(imptr_.get()) + : impl_(new implement) { + impl_->widget_ptr = nullptr; impl_->react = true; impl_->radio = false; } drawer::~drawer() - {} + { + delete impl_; + } void drawer::attached(widget_reference widget, graph_reference) { - widget_ = &widget; + impl_->widget_ptr = &widget; } void drawer::refresh(graph_reference graph) { - _m_draw_background(graph); - _m_draw_title(graph); - _m_draw_checkbox(graph, graph.text_extent_size(L"jN", 2).height + 2); + auto wdg = impl_->widget_ptr; + + //draw background + if (bground_mode::basic != API::effects_bground_mode(*wdg)) + graph.rectangle(true, wdg->bgcolor()); + + //draw title + if (graph.width() > 16 + interval) + { + auto title = to_wstring(wdg->caption_native()); + unsigned pixels = graph.width() - (16 + interval); + + nana::paint::text_renderer tr(graph); + if (!wdg->enabled()) + { + graph.palette(true, colors::white); + tr.render({ 17 + interval, 2 }, title.c_str(), title.length(), pixels); + graph.palette(true, static_cast(0x808080)); + } + else + graph.palette(true, wdg->fgcolor()); + + tr.render({ 16 + interval, 1 }, title.c_str(), title.length(), pixels); + } + + //draw crook + auto txt_px = graph.text_extent_size(L"jN", 2).height + 2; + impl_->crook.draw(graph, wdg->bgcolor(), wdg->fgcolor(), rectangle(0, txt_px > 16 ? (txt_px - 16) / 2 : 0, 16, 16), API::element_state(*wdg)); } void drawer::mouse_down(graph_reference graph, const arg_mouse&) @@ -63,8 +92,8 @@ namespace checkbox if (impl_->react) { impl_->crook.reverse(); - arg_checkbox arg{ static_cast(widget_) }; - API::events(widget_->handle()).checked.emit(arg); + arg_checkbox arg{ static_cast(impl_->widget_ptr) }; + API::events(impl_->widget_ptr->handle()).checked.emit(arg); } refresh(graph); API::lazy_refresh(); @@ -86,39 +115,6 @@ namespace checkbox { return impl_; } - - void drawer::_m_draw_background(graph_reference graph) - { - if(bground_mode::basic != API::effects_bground_mode(*widget_)) - graph.rectangle(true, API::bgcolor(*widget_)); - } - - void drawer::_m_draw_checkbox(graph_reference graph, unsigned first_line_height) - { - impl_->crook.draw(graph, widget_->bgcolor(), widget_->fgcolor(), rectangle(0, first_line_height > 16 ? (first_line_height - 16) / 2 : 0, 16, 16), API::element_state(*widget_)); - } - - void drawer::_m_draw_title(graph_reference graph) - { - if (graph.width() > 16 + interval) - { - std::wstring title = ::nana::charset(widget_->caption(), ::nana::unicode::utf8); - - unsigned pixels = graph.width() - (16 + interval); - - nana::paint::text_renderer tr(graph); - if (API::window_enabled(widget_->handle()) == false) - { - graph.palette(true, colors::white); - tr.render({ 17 + interval, 2 }, title.c_str(), title.length(), pixels); - graph.palette(true, { 0x80, 0x80, 0x80 }); - } - else - graph.palette(true, widget_->fgcolor()); - - tr.render({ 16 + interval, 1 }, title.c_str(), title.length(), pixels); - } - } //end class drawer } //end namespace checkbox }//end namespace drawerbase @@ -209,6 +205,7 @@ namespace checkbox e.uiobj->react(true); API::umake_event(e.eh_checked); API::umake_event(e.eh_destroy); + API::umake_event(e.eh_keyboard); } } diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index c6f0ca1f..ed6c2828 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -851,7 +851,7 @@ namespace nana throw_not_utf8(str); drawerbase::label::renderer rd; rd.format(format_enabled); - rd.parse(utf8_cast(str)); + rd.parse(to_wstring(str)); return rd.measure(graph, allowed_width_in_pixel, h_align, v_align); } diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 34e85650..fc6086cc 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1,7 +1,7 @@ /* * A text editor implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -1255,11 +1255,12 @@ namespace nana{ namespace widgets return (a.begin < b.begin); }); - auto previous = entities.begin(); - auto i = previous + 1; - while(i != entities.end()) + auto i = entities.begin(); + auto bound = i->end; + + for (++i; i != entities.end(); ) { - if (previous->end > i->begin) + if (bound > i->begin) i = entities.erase(i); // erase overlaping. Left only the first. else ++i; @@ -1321,7 +1322,7 @@ namespace nana{ namespace widgets auto sp = std::make_shared(); sp->fgcolor = fgcolor; sp->bgcolor = bgcolor; - keywords_->schemes[name] = sp; + keywords_->schemes[name].swap(sp); } void text_editor::erase_highlight(const std::string& name) diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 95dacd30..6c69b362 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -319,7 +319,7 @@ namespace drawerbase { std::wstring line_text; if (editor->getline(line_index, line_text)) { - text = utf8_cast(line_text); + text = to_utf8(line_text); return true; } } diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index 6c053df2..73913ba3 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -343,8 +343,8 @@ namespace nana else { wchar_t wstr[2] = { key, 0 }; - pattern += utf8_cast(wstr); - track_node.key_buf += utf8_cast(wstr); + pattern += to_utf8(wstr); + track_node.key_buf += to_utf8(wstr); } const node_type *begin = node_state.selected ? node_state.selected : attr.tree_cont.get_root()->child; @@ -995,7 +995,7 @@ namespace nana bool item_proxy::operator==(const wchar_t* s) const { - return (node_ && s && (node_->value.second.text == utf8_cast(s))); + return (node_ && s && (node_->value.second.text == to_utf8(s))); } // Behavior of Iterator diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 65d537c7..3a84ca17 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -949,8 +949,7 @@ namespace paint void graphics::string(const point& pos, const std::string& text_utf8) { - throw_not_utf8(text_utf8); - string(pos, utf8_cast(text_utf8)); + string(pos, to_wstring(text_utf8)); } void graphics::string(const point& pos, const std::string& text_utf8, const color& clr) diff --git a/source/system/dataexch.cpp b/source/system/dataexch.cpp index cf18c153..992a76d3 100644 --- a/source/system/dataexch.cpp +++ b/source/system/dataexch.cpp @@ -43,7 +43,7 @@ namespace nana{ namespace system{ #ifdef NANA_WINDOWS _m_set(format::text, text.c_str(), (text.length() + 1) * sizeof(wchar_t)); #else - std::string str = utf8_cast(text); + std::string str = to_utf8(text); _m_set(format::text, str.c_str(), str.size() + 1); #endif } @@ -129,7 +129,7 @@ namespace nana{ namespace system{ if (pos != wstr.npos) wstr.erase(pos + 1); - text_utf8 = utf8_cast(wstr); + text_utf8 = to_utf8(wstr); #else text_utf8.reserve(size); text_utf8.append(reinterpret_cast(res), reinterpret_cast(res) + size); @@ -169,7 +169,7 @@ namespace nana{ namespace system{ text_utf8.erase(pos + 1); ::XFree(res); - str = utf8_cast(text_utf8); + str = to_wstring(text_utf8); #endif } }