From f4924ef2f8600fafa82d3fc0d1c4d5f9eea0c738 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 3 Aug 2015 01:37:36 +0800 Subject: [PATCH] add throw() for some functions --- include/nana/gui/programming_interface.hpp | 2 +- include/nana/gui/widgets/combox.hpp | 16 ++++++------- include/nana/gui/widgets/group.hpp | 2 +- include/nana/gui/widgets/label.hpp | 7 +++--- include/nana/gui/widgets/spinbox.hpp | 2 +- include/nana/gui/widgets/textbox.hpp | 4 ++-- include/nana/gui/widgets/widget.hpp | 6 ++--- source/gui/detail/win32/bedrock.cpp | 28 ++++++++++------------ source/gui/programming_interface.cpp | 12 +++++----- source/gui/widgets/combox.cpp | 8 +++---- source/gui/widgets/group.cpp | 2 +- source/gui/widgets/label.cpp | 12 +++------- source/gui/widgets/spinbox.cpp | 16 ++++++------- source/gui/widgets/textbox.cpp | 2 +- source/gui/widgets/widget.cpp | 12 +++++----- 15 files changed, 60 insertions(+), 71 deletions(-) diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 7db38a0a..167fd8d8 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -61,7 +61,7 @@ namespace API widget_colors* get_scheme(window); void attach_drawer(widget&, drawer_trigger&); - nana::string window_caption(window); + nana::string window_caption(window) throw(); void window_caption(window, nana::string); window create_window(window, bool nested, const rectangle&, const appearance&, widget* attached); diff --git a/include/nana/gui/widgets/combox.hpp b/include/nana/gui/widgets/combox.hpp index 16b22faf..beb1cece 100644 --- a/include/nana/gui/widgets/combox.hpp +++ b/include/nana/gui/widgets/combox.hpp @@ -3,8 +3,8 @@ * Nana C++ Library(http://www.nanapro.org) * 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 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/gui/widgets/combox.hpp @@ -43,7 +43,7 @@ namespace nana }; class drawer_impl; - + class trigger : public drawer_trigger { @@ -101,7 +101,7 @@ namespace nana throw std::runtime_error("combox::item_proxy.value() invalid type of value"); return *p; } - + template item_proxy& value(const T& t) { @@ -169,7 +169,7 @@ namespace nana combox(window, nana::string, bool visible = true); combox(window, const nana::char_t*, bool visible = true); combox(window, const rectangle& r = rectangle(), bool visible = true); - + void clear(); void editable(bool); bool editable() const; @@ -209,8 +209,8 @@ namespace nana _m_erase(p.get()); } - /// \brief Set user-defined item renderer object. - /// It is an address therefore the user should not destroy the renderer object + /// \brief Set user-defined item renderer object. + /// It is an address therefore the user should not destroy the renderer object /// after it is set to the combox. Passing null_ptr cancels the user-defined renderer object. void renderer(item_renderer*); @@ -224,7 +224,7 @@ namespace nana const drawerbase::combox::drawer_impl& _m_impl() const; private: //Overrides widget's virtual functions - nana::string _m_caption() const override; + nana::string _m_caption() const throw() override; void _m_caption(nana::string&&) override; nana::any * _m_anyobj(std::size_t pos, bool alloc_if_empty) const override; }; diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index 058e3993..82f34a5b 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -77,7 +77,7 @@ namespace nana{ void _m_add_child(const char* field, widget*); void _m_init(); void _m_complete_creation() override; - ::nana::string _m_caption() const override; + ::nana::string _m_caption() const throw() override; void _m_caption(::nana::string&&) override; private: std::unique_ptr impl_; diff --git a/include/nana/gui/widgets/label.hpp b/include/nana/gui/widgets/label.hpp index 3142beec..6d72cd4e 100644 --- a/include/nana/gui/widgets/label.hpp +++ b/include/nana/gui/widgets/label.hpp @@ -58,16 +58,15 @@ namespace nana label(); label(window, bool visible); label(window, const nana::string& text, bool visible = true); - label(window, const nana::char_t* text, bool visible = true); label(window, const rectangle& = {}, bool visible = true); label& transparent(bool); ///< Switchs the label widget to the transparent background mode. - bool transparent() const; + bool transparent() const throw(); label& format(bool); ///< Switches the format mode of the widget. label& add_format_listener(std::function); - void click_for(window associated_window); // as same as the "for" attribute of a label + label& click_for(window associated_window) throw(); // as same as the "for" attribute of a label - /// \briefReturn the size of the text. If *allowed_width_in_pixel* is not zero, returns a + /// Returns the size of the text. If *allowed_width_in_pixel* is not zero, returns a /// "corrected" size that changes lines to fit the text into the specified width nana::size measure(unsigned allowed_width_in_pixel) const; diff --git a/include/nana/gui/widgets/spinbox.hpp b/include/nana/gui/widgets/spinbox.hpp index df962c39..22b780e4 100644 --- a/include/nana/gui/widgets/spinbox.hpp +++ b/include/nana/gui/widgets/spinbox.hpp @@ -106,7 +106,7 @@ namespace nana void modifier(std::wstring prefix, std::wstring suffix); void modifier(const std::string & prefix_utf8, const std::string& suffix_utf8); private: - ::nana::string _m_caption() const; + ::nana::string _m_caption() const throw(); void _m_caption(::nana::string&&); }; //end class spinbox diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index a678d31c..1d46d33b 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -149,7 +149,7 @@ namespace nana /// Appends an string. If `at_caret` is `true`, the string is inserted at the position of caret, otherwise, it is appended at end of the textbox. textbox& append(const nana::string& text, bool at_caret); - /// Determine wheter the text is line wrapped. + /// Determine wheter the text is line wrapped. bool line_wrapped() const; textbox& line_wrapped(bool); @@ -187,7 +187,7 @@ namespace nana void erase_keyword(const nana::string& kw); protected: //Overrides widget's virtual functions - ::nana::string _m_caption() const override; + ::nana::string _m_caption() const throw() override; void _m_caption(::nana::string&&) override; void _m_typeface(const paint::font&) override; }; diff --git a/include/nana/gui/widgets/widget.hpp b/include/nana/gui/widgets/widget.hpp index 67bb3cc8..18163f61 100644 --- a/include/nana/gui/widgets/widget.hpp +++ b/include/nana/gui/widgets/widget.hpp @@ -41,9 +41,9 @@ namespace nana window parent() const; - nana::string caption() const; + nana::string caption() const throw(); void caption(std::string utf8); - void caption(nana::string); + void caption(std::wstring); template void i18n(std::string msgid, Args&&... args) @@ -105,7 +105,7 @@ namespace nana virtual void _m_complete_creation(); virtual general_events& _m_get_general_events() const = 0; - virtual nana::string _m_caption() const; + virtual nana::string _m_caption() const throw(); virtual void _m_caption(nana::string&&); virtual nana::cursor _m_cursor() const; virtual void _m_cursor(nana::cursor); diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/win32/bedrock.cpp index 9d98f2fe..d8ac543c 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/win32/bedrock.cpp @@ -1305,26 +1305,22 @@ namespace detail brock.event_move(msgwnd, (int)(short) LOWORD(lParam), (int)(short) HIWORD(lParam)); break; case WM_PAINT: - if (msgwnd->is_draw_through()) { - msgwnd->other.attribute.root->draw_through(); - ::PAINTSTRUCT ps; ::BeginPaint(root_window, &ps); + if (msgwnd->is_draw_through()) + { + msgwnd->other.attribute.root->draw_through(); + } + else + { + //Don't copy root_graph to the window directly, otherwise the edge nimbus effect will be missed. + ::nana::rectangle update_area(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top); + if (!update_area.empty()) + msgwnd->drawer.map(reinterpret_cast(msgwnd), true, &update_area); + } ::EndPaint(root_window, &ps); - } - else - { - ::PAINTSTRUCT ps; - ::HDC dc = ::BeginPaint(root_window, &ps); - - //Don't copy root_graph to the window directly, otherwise the edge nimbus effect will be missed. - ::nana::rectangle update_area(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top); - if (!update_area.empty()) - msgwnd->drawer.map(reinterpret_cast(msgwnd), true, &update_area); - - ::EndPaint(root_window, &ps); - } + } break; case WM_SYSCHAR: def_window_proc = true; diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 3c75b106..e70f64eb 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -112,7 +112,7 @@ namespace API iwd->effect.bground = new_effect_ptr; iwd->effect.bground_fade_rate = fade_rate; restrict::window_manager.enable_effects_bground(iwd, true); - + if (fade_rate < 0.01) iwd->flags.make_bground_declared = true; @@ -184,7 +184,7 @@ namespace API } } - nana::string window_caption(window wd) + nana::string window_caption(window wd) throw() { auto const iwd = reinterpret_cast(wd); internal_scope_guard isg; @@ -559,7 +559,7 @@ namespace API { if (category::flags::root != iwd->other.category) iwd = iwd->seek_non_lite_widget_ancestor(); - + restrict::window_manager.update(iwd, false, false); } } @@ -640,7 +640,7 @@ namespace API internal_scope_guard lock; if (!restrict::window_manager.available(iwd)) return{}; - + auto sz = window_size(wd); sz.width += iwd->extra_width; sz.height += iwd->extra_height; @@ -774,7 +774,7 @@ namespace API if (restrict::window_manager.available(iwd)) iwd->widget_notifier->caption(title); } - + nana::string window_caption(window wd) { auto const iwd = reinterpret_cast(wd); @@ -931,7 +931,7 @@ namespace API if (prev != clr) { iwd->scheme->background = clr; - + //If the bground mode of this window is basic, it should remake the background if (iwd->effect.bground && iwd->effect.bground_fade_rate < 0.01) // fade rate < 0.01 means it is basic mode iwd->flags.make_bground_declared = true; diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index 2ddb22f6..c6f3a32f 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -201,7 +201,7 @@ namespace nana if (new_where == state_.pointer_where) return false; - + state_.pointer_where = new_where; return true; } @@ -261,7 +261,7 @@ namespace nana state_.lister->move_items(upwards, circle); return; } - + auto pos = module_.index; if (upwards) { @@ -412,7 +412,7 @@ namespace nana { if (image_pixels_ == px) return false; - + image_pixels_ = px; return true; } @@ -988,7 +988,7 @@ namespace nana API::refresh_window(*this); } - nana::string combox::_m_caption() const + nana::string combox::_m_caption() const throw() { internal_scope_guard lock; auto editor = _m_impl().editor(); diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index 7380ff11..37fb20e1 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -234,7 +234,7 @@ namespace nana{ _m_init(); } - ::nana::string group::_m_caption() const + ::nana::string group::_m_caption() const throw() { return impl_->caption.caption(); } diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index a7eba8ae..6639bc53 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -779,13 +779,6 @@ namespace nana caption(text); } - label::label(window wd, const nana::char_t* text, bool visible) - { - create(wd, rectangle(), visible); - bgcolor(API::bgcolor(wd)); - caption(text); - } - label::label(window wd, const rectangle& r, bool visible) { create(wd, r, visible); @@ -801,7 +794,7 @@ namespace nana return *this; } - bool label::transparent() const + bool label::transparent() const throw() { return (bground_mode::basic == API::effects_bground_mode(*this)); } @@ -825,9 +818,10 @@ namespace nana return *this; } - void label::click_for(window associated_window) + label& label::click_for(window associated_window) throw() { get_drawer_trigger().impl()->for_associated_wd = associated_window; + return *this; } nana::size label::measure(unsigned limited) const diff --git a/source/gui/widgets/spinbox.cpp b/source/gui/widgets/spinbox.cpp index 0f22fd4c..39083fd9 100644 --- a/source/gui/widgets/spinbox.cpp +++ b/source/gui/widgets/spinbox.cpp @@ -86,7 +86,7 @@ namespace nana ss >> v; if (v < begin_ || last_ < v) return false; - + diff = (value_ != v); value_ = v; return true; @@ -297,7 +297,7 @@ namespace nana bool diff; if (!range_->value(value_str, diff)) return false; - + if (diff) reset_text(); return true; @@ -403,7 +403,7 @@ namespace nana _m_draw_spins(buttons::none); return true; } - + return false; } @@ -435,7 +435,7 @@ namespace nana auto size = API::window_size(editor_->window_handle()); if (size.width > 18) return{ static_cast(size.width - 16), 0, 16, size.height }; - + return{ 0, 0, size.width, size.height }; } @@ -513,7 +513,7 @@ namespace nana { impl_->attach(wdg, graph); } - + void drawer::refresh(graph_reference) { impl_->render(); @@ -526,7 +526,7 @@ namespace nana impl_->editor()->reset_caret(); API::lazy_refresh(); } - + void drawer::mouse_wheel(graph_reference, const arg_wheel& arg) { impl_->mouse_wheel(arg.upwards); @@ -557,7 +557,7 @@ namespace nana impl_->render(); API::lazy_refresh(); } - + void drawer::key_press(graph_reference, const arg_keyboard& arg) { if (impl_->editor()->respond_key(arg)) @@ -682,7 +682,7 @@ namespace nana modifier(static_cast(::nana::charset(prefix_utf8, ::nana::unicode::utf8)), static_cast(::nana::charset(suffix_utf8, ::nana::unicode::utf8))); } - ::nana::string spinbox::_m_caption() const + ::nana::string spinbox::_m_caption() const throw() { internal_scope_guard lock; auto editor = get_drawer_trigger().impl()->editor(); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index e5e98068..5f600f1c 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -515,7 +515,7 @@ namespace drawerbase { } //Override _m_caption for caption() - nana::string textbox::_m_caption() const + nana::string textbox::_m_caption() const throw() { internal_scope_guard lock; auto editor = get_drawer_trigger().editor(); diff --git a/source/gui/widgets/widget.cpp b/source/gui/widgets/widget.cpp index d4d20387..af853b38 100644 --- a/source/gui/widgets/widget.cpp +++ b/source/gui/widgets/widget.cpp @@ -2,8 +2,8 @@ * The fundamental widget class implementation * 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 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/gui/widgets/widget.cpp @@ -54,7 +54,7 @@ namespace nana widget& wdg_; }; - nana::string widget::caption() const + nana::string widget::caption() const throw() { return this->_m_caption(); } @@ -64,7 +64,7 @@ namespace nana _m_caption(std::wstring(::nana::charset(utf8, ::nana::unicode::utf8))); } - void widget::caption(nana::string str) + void widget::caption(std::wstring str) { _m_caption(std::move(str)); } @@ -125,7 +125,7 @@ namespace nana bool widget::empty() const { - return (nullptr == handle()); + return (nullptr == handle()); } void widget::focus() @@ -252,7 +252,7 @@ namespace nana void widget::_m_complete_creation() {} - nana::string widget::_m_caption() const + nana::string widget::_m_caption() const throw() { return API::dev::window_caption(handle()); }