code reviews

This commit is contained in:
Jinhao
2015-10-13 01:38:53 +08:00
parent 500aa030ae
commit 1b5aed2e5f
41 changed files with 830 additions and 1001 deletions

View File

@@ -1,95 +0,0 @@
/*
* Exception Definition
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
*
* 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/exceptions.hpp
*/
#ifndef NANA_EXCEPTIONS_H
#define NANA_EXCEPTIONS_H
#include <exception>
#include <string>
namespace nana
{
/**
* nana::threads::thread::exit throws this exception to exit thread
* this exception is not allowed to be catch by programmer,
* otherwise the thread may not exit
*/
class thrd_exit: public std::exception
{
public:
thrd_exit(unsigned retval);
~thrd_exit() throw();
const char* what() const throw();
unsigned retval() const;
private:
unsigned retval_;
};
/**
* nana::text::settings_t throws this exception if it dose not found a given member
* in a scope
*/
class bad_member: public std::exception
{
public:
bad_member(const std::string& what);
~bad_member() throw();
const char* what() const throw();
private:
std::string what_;
};
/**
* nana::text::settings_t throws this exception if there is a syntax error
*/
class bad_syntax: public std::exception
{
public:
bad_syntax(const std::string& what);
~bad_syntax() throw();
const char* what() const throw();
private:
std::string what_;
};
class bad_error: public std::exception
{
public:
bad_error(const std::string& what);
~bad_error() throw();
const char* what() const throw();
private:
std::string what_;
};
class bad_handle: public std::exception
{
public:
bad_handle(const std::string& what);
~bad_handle() throw();
const char* what() const throw();
private:
std::string what_;
};
class bad_window
:public std::exception
{
public:
bad_window(const char* what);
~bad_window() throw();
const char* what() const throw();
private:
std::string what_;
};
}// end namespace nana
#endif

View File

@@ -12,9 +12,6 @@
#ifndef NANA_GUI_DETAIL_BEDROCK_HPP
#define NANA_GUI_DETAIL_BEDROCK_HPP
#include "window_manager.hpp"
#include "events_operation.hpp"
#include "runtime_manager.hpp"
#include "general_events.hpp"
#include "color_schemes.hpp"
#include "internal_scope_guard.hpp"
@@ -23,9 +20,11 @@ namespace nana
{
namespace detail
{
struct native_interface;
class element_store;
class element_store;
class events_operation;
struct basic_window;
class window_manager;
//class bedrock
//@brief: bedrock is a fundamental core component, it provides a abstract to the OS platform
@@ -34,9 +33,7 @@ namespace detail
{
bedrock();
public:
typedef native_interface interface_type;
typedef window_manager window_manager_t;
typedef window_manager_t::core_window_t core_window_t;
using core_window_t = basic_window;
struct thread_context;
@@ -53,7 +50,6 @@ namespace detail
::nana::category::flags category(core_window_t*);
core_window_t* focus();
native_window_type root(core_window_t*);
void set_menubar_taken(core_window_t*);
@@ -83,14 +79,13 @@ namespace detail
void undefine_state_cursor(core_window_t*, thread_context*);
widget_colors& get_scheme_template(scheme_factory_base&&);
std::unique_ptr<widget_colors> make_scheme(scheme_factory_base&&);
widget_colors* make_scheme(scheme_factory_base&&);
events_operation& evt_operation();
window_manager& wd_manager();
void manage_form_loader(core_window_t*, bool insert_or_remove);
public:
events_operation evt_operation;
window_manager_t wd_manager;
runtime_manager<core_window_t*, bedrock> rt_manager;
bool emit(event_code, core_window_t*, const arg_mouse&, bool ask_update, thread_context*);
bool emit(event_code, core_window_t*, const event_arg&, bool ask_update, thread_context*);
bool emit_drawer(event_code, core_window_t*, const event_arg&, thread_context*);
private:

View File

@@ -3,6 +3,9 @@
#include <nana/gui/detail/bedrock.hpp>
#include "color_schemes.hpp"
#include "events_operation.hpp"
#include "window_manager.hpp"
#include <set>
namespace nana
{
@@ -10,8 +13,10 @@ namespace nana
{
struct bedrock::pi_data
{
color_schemes scheme;
color_schemes scheme;
events_operation evt_operation;
window_manager wd_manager;
std::set<core_window_t*> auto_form_set;
};
}
}

View File

@@ -14,7 +14,6 @@
#define NANA_DETAIL_COLOR_SCHEMES_HPP
#include "widget_colors.hpp"
#include <nana/pat/cloneable.hpp>
namespace nana
{
@@ -27,8 +26,8 @@ namespace nana
virtual ~scheme_factory_base() = default;
virtual factory_identifier* get_id() const = 0;
virtual std::unique_ptr<widget_colors> create() = 0;
virtual std::unique_ptr<widget_colors> create(widget_colors&) = 0;
virtual widget_colors* create() = 0;
virtual widget_colors* create(widget_colors&) = 0;
};
template<typename Scheme>
@@ -41,14 +40,14 @@ namespace nana
return &fid_;
}
std::unique_ptr<widget_colors> create() override
widget_colors* create() override
{
return std::unique_ptr<widget_colors>(new Scheme);
return (new Scheme);
}
std::unique_ptr<widget_colors> create(widget_colors& other) override
widget_colors* create(widget_colors& other) override
{
return std::unique_ptr<widget_colors>{new Scheme(static_cast<Scheme&>(other))};
return (new Scheme(static_cast<Scheme&>(other)));
}
private:
static factory_identifier fid_;
@@ -71,7 +70,7 @@ namespace nana
~color_schemes();
scheme& scheme_template(scheme_factory_base&&);
std::unique_ptr<scheme> create(scheme_factory_base&&);
scheme* create(scheme_factory_base&&);
private:
implement * impl_;
};

View File

@@ -4,6 +4,7 @@
#include <nana/paint/graphics.hpp>
#include <nana/paint/pixel_buffer.hpp>
#include <nana/gui/layout_utility.hpp>
#include <nana/gui/detail/window_layout.hpp>
namespace nana{
namespace detail
@@ -14,7 +15,7 @@ namespace nana{
edge_nimbus_renderer() = default;
public:
using core_window_t = CoreWindow;
using window_layer = window_layout;
using window_layer = ::nana::detail::window_layout;
using graph_reference = ::nana::paint::graphics&;
static edge_nimbus_renderer& instance()

View File

@@ -6,9 +6,9 @@
#include <unordered_map>
#if defined(NANA_MINGW) && defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_mutex.hpp>
#include <nana/std_mutex.hpp>
#else
#include <mutex>
#include <mutex>
#endif
namespace nana
@@ -24,8 +24,8 @@ namespace nana
void cancel(event_handle);
void erase(event_handle);
private:
mutable std::recursive_mutex mutex_;
std::unordered_set<event_handle> register_;
std::recursive_mutex mutex_;
std::unordered_set<event_handle> handles_;
std::unordered_map<window, std::shared_ptr<general_events>> evt_table_;
};
}//end namespace detail

View File

@@ -1,100 +0,0 @@
/*
* A Runtime Manager Implementation
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
*
* 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/detail/runtime_manager.hpp
*
*/
#ifndef NANA_GUI_DETAIL_RUNTIME_MANAGER_HPP
#define NANA_GUI_DETAIL_RUNTIME_MANAGER_HPP
#include <map>
namespace nana
{
namespace detail
{
template<typename Window, typename Bedrock>
class runtime_manager
{
public:
typedef Window window_handle;
template<typename Form, typename... Args>
Form* create_form(Args&&... args)
{
widget_placer<Form> * holder = new widget_placer<Form>;
if (holder->create(std::forward<Args>(args)...))
{
holder_[holder->get_handle()] = holder;
return holder->get();
}
delete holder;
return nullptr;
}
void remove_if_exists(window_handle wd)
{
auto i = holder_.find(wd);
if(i != holder_.cend())
{
delete i->second;
holder_.erase(i);
}
}
private:
class widget_holder
{
public:
virtual ~widget_holder(){}
virtual window_handle get_handle() const = 0;
};
template<typename Form>
class widget_placer : public widget_holder
{
public:
widget_placer()
: form_(nullptr)
{}
~widget_placer()
{
delete form_;
}
template<typename... Args>
bool create(Args&&... args)
{
if (nullptr == form_)
form_ = new Form(std::forward<Args>(args)...);
return (form_ && !form_->empty());
}
Form* get() const
{
return form_;
}
window_handle get_handle() const override
{
return reinterpret_cast<window_handle>(form_ ? form_->handle() : nullptr);
}
private:
Form * form_;
};
private:
std::map<window_handle, widget_holder*> holder_;
}; //end class runtime_manager
}//end namespace detail
}//end namespace nana
#endif

View File

@@ -134,7 +134,6 @@ namespace detail
bool get_graphics(core_window_t*, nana::paint::graphics&);
bool get_visual_rectangle(core_window_t*, nana::rectangle&);
::nana::widget* get_widget(core_window_t*) const;
std::vector<core_window_t*> get_children(core_window_t*) const;
bool set_parent(core_window_t* wd, core_window_t* new_parent);
core_window_t* set_focus(core_window_t*, bool root_has_been_focused);

View File

@@ -47,7 +47,7 @@ namespace nana
public:
bground_transparent(std::size_t percent);
private:
virtual bground_interface* create() const;
bground_interface* create() const override;
private:
std::size_t percent_;
};
@@ -58,7 +58,7 @@ namespace nana
public:
bground_blur(std::size_t radius);
private:
virtual bground_interface * create() const;
bground_interface * create() const override;
private:
std::size_t radius_;
};

View File

@@ -13,9 +13,9 @@
#ifndef NANA_GUI_PROGRAMMING_INTERFACE_HPP
#define NANA_GUI_PROGRAMMING_INTERFACE_HPP
#include <nana/config.hpp>
#include "detail/bedrock.hpp"
#include "effects.hpp"
#include "detail/general_events.hpp"
#include "detail/color_schemes.hpp"
#include <nana/paint/image.hpp>
#include <memory>
@@ -44,6 +44,11 @@ namespace nana
namespace API
{
namespace detail
{
::nana::widget_colors* make_scheme(::nana::detail::scheme_factory_base&&);
}
void effects_edge_nimbus(window, effects::edge_nimbus);
effects::edge_nimbus effects_edge_nimbus(window);
@@ -60,8 +65,7 @@ namespace API
template<typename Scheme>
std::unique_ptr<Scheme> make_scheme()
{
return std::unique_ptr<Scheme>(
static_cast<Scheme*>(::nana::detail::bedrock::instance().make_scheme(::nana::detail::scheme_factory<Scheme>()).release()));
return std::unique_ptr<Scheme>{static_cast<Scheme*>(API::detail::make_scheme(::nana::detail::scheme_factory<Scheme>()))};
}
void set_scheme(window, widget_colors*);
@@ -82,9 +86,56 @@ namespace API
}//end namespace dev
widget* get_widget(window);
namespace detail
{
general_events* get_general_events(window);
bool emit_event(event_code, window, const ::nana::event_arg&);
class enum_widgets_function_base
{
public:
virtual ~enum_widgets_function_base() = default;
void enum_widgets(window, bool recursive);
private:
virtual bool _m_enum_fn(::nana::widget*) = 0;
};
template<typename Widget, typename EnumFunction>
class enum_widgets_function
: public enum_widgets_function_base
{
public:
enum_widgets_function(EnumFunction && enum_fn)
: enum_fn_(static_cast<EnumFunction&&>(enum_fn))
{}
private:
bool _m_enum_fn(::nana::widget* wd) override
{
return _m_enum_call<Widget>(wd, nullptr);
}
template<typename T, typename std::enable_if<std::is_same<::nana::widget, T>::value>::type* = nullptr>
bool _m_enum_call(::nana::widget* wd)
{
enum_fn_(*wd);
return true;
}
template<typename T, typename std::enable_if<!std::is_same<::nana::widget, T>::value>::type* = nullptr>
bool _m_enum_call(::nana::widget* wd)
{
auto ptr = dynamic_cast<Widget*>(wd);
if (nullptr == ptr)
return false;
enum_fn_(*ptr);
return true;
}
private:
EnumFunction && enum_fn_;
};
}//end namespace detail
void exit();
@@ -98,25 +149,12 @@ namespace API
rectangle make_center(window, unsigned width, unsigned height); ///< Retrieves a rectangle which is in the center of the window
template<typename Widget=::nana::widget, typename EnumFunction>
void enum_widgets(window wd, bool recursive, EnumFunction && ef)
void enum_widgets(window wd, bool recursive, EnumFunction && fn)
{
static_assert(std::is_convertible<Widget, ::nana::widget>::value, "enum_widgets<Widget>: The specified Widget is not a widget type.");
typedef ::nana::detail::basic_window core_window_t;
auto & brock = ::nana::detail::bedrock::instance();
internal_scope_guard lock;
auto children = brock.wd_manager.get_children(reinterpret_cast<core_window_t*>(wd));
for (auto child : children)
{
auto wgt = dynamic_cast<Widget*>(brock.wd_manager.get_widget(child));
if (nullptr == wgt)
continue;
ef(*wgt);
if (recursive)
enum_widgets<Widget>(wd, recursive, std::forward<EnumFunction>(ef));
}
detail::enum_widgets_function<Widget, EnumFunction> enum_fn(static_cast<EnumFunction&&>(fn));
enum_fn.enum_widgets(wd, recursive);
}
void window_icon_default(const paint::image& small_icon, const paint::image& big_icon = {});
@@ -172,8 +210,7 @@ namespace API
template<typename EventArg, typename std::enable_if<std::is_base_of< ::nana::event_arg, EventArg>::value>::type* = nullptr>
bool emit_event(event_code evt_code, window wd, const EventArg& arg)
{
auto & brock = ::nana::detail::bedrock::instance();
return brock.emit(evt_code, reinterpret_cast< ::nana::detail::bedrock::core_window_t*>(wd), arg, true, brock.get_thread_context());
return detail::emit_event(evt_code, wd, arg);
}
void umake_event(event_handle);

View File

@@ -166,9 +166,7 @@ namespace nana
std::size_t pos_{0};
};
typedef std::vector<index_pair> selection;
using selection = std::vector<index_pair>;
/// struct essence_t
///@brief: this struct gives many data for listbox,
@@ -180,7 +178,7 @@ namespace nana
class drawer_lister_impl;
/// mostly works on display positions
class trigger: public drawer_trigger
class trigger: public drawer_trigger
{
public:
trigger();
@@ -208,9 +206,9 @@ namespace nana
drawer_lister_impl *drawer_lister_;
};//end class trigger
/// operate with absolute positions and contain only the position but montain pointers to parts of the real items
/// operate with absolute positions and contain only the position but montain pointers to parts of the real items
/// item_proxy self, it references and iterators are not invalidated by sort()
class item_proxy
class item_proxy
: public std::iterator<std::input_iterator_tag, item_proxy>
{
public:
@@ -445,18 +443,18 @@ namespace nana
size_type pos_{0}; ///< Absolute position, not relative to display, and dont change during sort()
};
struct export_options
{
nana::string sep = nana::string {STR("\t" )},
endl= nana::string {STR("\n")} ;
bool only_selected_items{true},
only_checked_items {false},
only_visible_columns{true};
struct export_options
{
nana::string sep = nana::string {STR("\t" )},
endl= nana::string {STR("\n")};
bool only_selected_items{true},
only_checked_items {false},
only_visible_columns{true};
using columns_indexs = std::vector<size_type>;
columns_indexs columns_order;
};
}
using columns_indexs = std::vector<size_type>;
columns_indexs columns_order;
};
}
}//end namespace drawerbase
struct arg_listbox

View File

@@ -1,7 +1,7 @@
/*
* Nana GUI Library Definition
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* 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
@@ -20,27 +20,42 @@
#include "widgets/form.hpp"
#include "drawing.hpp"
#include "msgbox.hpp"
#include "../exceptions.hpp"
namespace nana
{
template<typename Form, bool IsMakeVisible = true>
class form_loader
namespace detail
{
public:
template<typename... Args>
Form & operator()(Args &&... args) const
struct form_loader_private
{
Form* res = detail::bedrock::instance().rt_manager.create_form<Form>(std::forward<Args>(args)...);
if (nullptr == res)
throw nana::bad_window("form_loader.operator(): failed to create a window");
template<typename, bool> friend class form_loader;
private:
static void insert_form(::nana::widget*);
};
if (IsMakeVisible) res->show();
template<typename Form, bool IsVisible>
class form_loader
{
public:
template<typename... Args>
Form & operator()(Args &&... args) const
{
auto p = new Form(std::forward<Args>(args)...);
return *res;
}
if (p->empty())
throw std::logic_error("form_loader failed to create the form");
};
detail::form_loader_private::insert_form(p);
if (IsVisible)
p->show();
return *p;
}
};
}
template<typename Form, bool IsVisible = true>
using form_loader = detail::form_loader<Form, IsVisible>;
void exec();
}//end namespace nana

View File

@@ -1,7 +1,7 @@
/*
* Image Processor Algorithm Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* 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
@@ -233,9 +233,9 @@ namespace detail
std::size_t coef2 = el.iu * iv_minus_coef;
std::size_t coef3 = el.iu * iv;
i->element.red = static_cast<unsigned>((coef0 * col0.element.red + coef1 * col1.element.red + (coef2 * col2.element.red + coef3 * col3.element.red)) >> double_shift_size);
i->element.green = static_cast<unsigned>((coef0 * col0.element.green + coef1 * col1.element.green + (coef2 * col2.element.green + coef3 * col3.element.green)) >> double_shift_size);
i->element.blue = static_cast<unsigned>((coef0 * col0.element.blue + coef1 * col1.element.blue + (coef2 * col2.element.blue + coef3 * col3.element.blue)) >> double_shift_size);
i->element.red = static_cast<unsigned char>((coef0 * col0.element.red + coef1 * col1.element.red + (coef2 * col2.element.red + coef3 * col3.element.red)) >> double_shift_size);
i->element.green = static_cast<unsigned char>((coef0 * col0.element.green + coef1 * col1.element.green + (coef2 * col2.element.green + coef3 * col3.element.green)) >> double_shift_size);
i->element.blue = static_cast<unsigned char>((coef0 * col0.element.blue + coef1 * col1.element.blue + (coef2 * col2.element.blue + coef3 * col3.element.blue)) >> double_shift_size);
}
}
}

View File

@@ -13,6 +13,7 @@
#ifndef NANA_PAT_ABSFACTORY_HPP
#define NANA_PAT_ABSFACTORY_HPP
#include "cloneable.hpp"
#include <memory>
namespace nana

View File

@@ -14,7 +14,7 @@
#include <nana/deploy.hpp>
#include <nana/traits.hpp>
#include <nana/exceptions.hpp>
#include <stdexcept>
namespace nana
@@ -70,19 +70,19 @@ namespace system
typedef typename function_ptr<Function>::type fptr_type;
if(nana::traits::is_function_pointer<fptr_type>::value == false)
throw nana::bad_error("shared_wrapper::symbols, template<_Function> is not a function type or a function pointer type");
throw std::invalid_argument("shared_wrapper::symbols, template<_Function> is not a function type or a function pointer type");
if(symbol == 0)
throw nana::bad_handle("shared_wrapper::symbols, symbol is null string");
throw std::invalid_argument("shared_wrapper::symbols, symbol is null string");
if(impl_.handle == 0)
throw nana::bad_handle("shared_wrapper::symbols, empty handle");
throw std::logic_error("shared_wrapper::symbols, empty handle");
if(impl_.symbol != symbol)
{
void *result = detail::shared_helper::symbols(impl_.handle, symbol);
if(result == 0)
throw nana::bad_handle("shared_wrapper::symbols, empty proc address");
throw std::logic_error("shared_wrapper::symbols, empty proc address");
impl_.proc_address = result;
impl_.symbol = symbol;