Merge branch 'hotfix-1.4' into develop

This commit is contained in:
Jinhao
2016-09-24 09:58:44 +08:00
16 changed files with 349 additions and 145 deletions

View File

@@ -1,7 +1,7 @@
/**
* A Inline Widget Interface Definition
* 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
@@ -35,6 +35,9 @@ namespace nana
/// Returns the host widget of the indicator
virtual ::nana::widget& host() const = 0;
/// Returns the position of column
virtual std::size_t column() const = 0;
/// Modifies the value of a item specified by pos
virtual void modify(index_type pos, const value_type&) const = 0;
@@ -45,7 +48,7 @@ namespace nana
virtual void hovered(index_type) = 0;
};
template<typename Index, typename Value>
template<typename Index, typename Status, typename Value>
class inline_widget_notifier_interface
{
public:
@@ -55,6 +58,9 @@ namespace nana
/// A type to the value of the item
using value_type = Value;
/// A type to the status
using status_type = Status;
/// A typedef name of a inline widget indicator
using inline_indicator = inline_widget_indicator<index_type, value_type>;
@@ -70,6 +76,9 @@ namespace nana
/// A message to activate the inline widget to attach a specified item
virtual void activate(inline_indicator&, index_type) = 0;
/// A message to change the status
virtual void notify_status(status_type, bool) = 0;
/// A message to resize the inline widget
virtual void resize(const size&) = 0;

View File

@@ -676,8 +676,14 @@ namespace nana
using index_pairs = ::std::vector<index_pair>;
using inline_notifier_interface = detail::inline_widget_notifier_interface<index_pair, ::std::string>;
enum class inline_widget_status{
checked,
checking,
selected,
selecting
};
using inline_notifier_interface = detail::inline_widget_notifier_interface<index_pair, inline_widget_status, ::std::string>;
// struct essence
//@brief: this struct gives many data for listbox,

View File

@@ -143,7 +143,11 @@ namespace nana{ namespace widgets
std::wstring text() const;
/// Sets caret position through text coordinate.
void move_caret(const upoint&);
/**
* @param pos the text position
* @param reset indicates whether to reset the text position by the pos. If this parameter is true, the text position is set by pos. If the parameter is false, it only moves the UI caret to the specified position.
*/
bool move_caret(const upoint& pos, bool reset = false);
void move_caret_end();
void reset_caret_pixels() const;
void reset_caret();
@@ -184,6 +188,7 @@ namespace nana{ namespace widgets
void del();
void backspace(bool record_undo = true);
void undo(bool reverse);
void set_undo_queue_length(std::size_t len);
void move_ns(bool to_north); //Moves up and down
void move_left();
void move_right();

View File

@@ -237,6 +237,12 @@ namespace nana
/// E.g. Whether caret moves to left of selected content or moves to left of last position when left arrow key is pressed.
/// @param move_to_end determines whether to move caret to left of selected_content or to left of last position.
void select_behavior(bool move_to_end);
/// Sets the undo/redo queue length
/**
* @param len The length of the queue. If this parameter is zero, the undo/redo is disabled.
*/
void set_undo_queue_length(std::size_t len);
protected:
//Overrides widget's virtual functions
native_string_type _m_caption() const throw() override;

View File

@@ -158,11 +158,9 @@ namespace nana
: public widget
{
public:
~widget_base();
window handle() const override;
private:
void _m_notify_destroy() override final;
protected:
void _m_notify_destroy() override;
protected:
window handle_{ nullptr };
};
@@ -183,6 +181,11 @@ namespace nana
scheme_{ API::dev::make_scheme<Scheme>() }
{}
~widget_object()
{
API::close_window(handle());
}
event_type& events() const
{
return *events_;
@@ -239,6 +242,13 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
widget_base::_m_notify_destroy();
events_ = std::make_shared<Events>();
API::dev::set_events(handle_, events_);
}
private:
DrawerTrigger trigger_;
std::shared_ptr<Events> events_;
@@ -259,6 +269,11 @@ namespace nana
: events_{ std::make_shared<Events>() }, scheme_{ API::dev::make_scheme<scheme_type>() }
{}
~widget_object()
{
API::close_window(handle());
}
event_type& events() const
{
return *events_;
@@ -292,6 +307,13 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
widget_base::_m_notify_destroy();
events_ = std::make_shared<Events>();
API::dev::set_events(handle_, events_);
}
private:
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
@@ -319,6 +341,11 @@ namespace nana
_m_bind_and_attach();
}
~widget_object()
{
API::close_window(handle());
}
event_type& events() const
{
return *events_;
@@ -419,6 +446,13 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
widget_base::_m_notify_destroy();
events_ = std::make_shared<Events>();
API::dev::set_events(handle_, events_);
}
private:
DrawerTrigger trigger_;
std::shared_ptr<Events> events_;
@@ -444,6 +478,11 @@ namespace nana
: events_{ std::make_shared<Events>() }, scheme_{ API::dev::make_scheme<scheme_type>() }
{}
~widget_object()
{
API::close_window(handle());
}
event_type& events() const
{
return *events_;

View File

@@ -15,6 +15,8 @@
#define NANA_PAT_ABSFACTORY_HPP
#include "cloneable.hpp"
#include <memory>
#include <tuple>
#include <type_traits>
namespace nana
{
@@ -43,21 +45,68 @@ namespace nana
namespace detail
{
template<typename T, typename Interface>
template<typename Useless, std::size_t ...Index>
struct pack{
using type = pack;
};
template<bool Negative, bool Zero, class IntConst, class Pack>
struct make_pack_helper
{ // explodes gracefully below 0
static_assert(!Negative,
"make_integer_sequence<T, N> requires N to be non-negative.");
};
template<typename Useless, std::size_t ... Vals>
struct make_pack_helper<false, true,
std::integral_constant<std::size_t, 0>,
pack<Useless, Vals...> >
: pack<Useless, Vals...>
{ // ends recursion at 0
};
template<typename Useless, std::size_t X, std::size_t... Vals>
struct make_pack_helper<false, false,
std::integral_constant<std::size_t, X>,
pack<Useless, Vals...> >
: make_pack_helper<false, X == 1,
std::integral_constant<std::size_t, X - 1>,
pack<Useless, X - 1, Vals...> >
{ // counts down to 0
};
template<std::size_t Size>
using make_pack = typename make_pack_helper<Size < 0, Size == 0, std::integral_constant<std::size_t, Size>, pack<int> >::type;
template<typename T, typename Interface, typename ...Args>
class abs_factory
: public abstract_factory<Interface>
{
std::unique_ptr<Interface> create() override
{
return std::unique_ptr<Interface>{ new T };
constexpr auto Size = std::tuple_size<decltype(args_)>::value;
return std::unique_ptr<Interface>{ _m_new(make_pack<Size>{}) };
}
template<std::size_t ... Index>
Interface* _m_new(const pack<int, Index...> &)
{
return new T(std::get<Index>(args_)...);
}
public:
abs_factory(const Args&... args)
: args_(args...)
{
}
private:
std::tuple<Args...> args_;
};
}//end namespace detail
template<typename Type>
pat::cloneable<abstract_factory<typename Type::factory_interface>> make_factory()
template<typename Type, typename ...Args>
pat::cloneable<abstract_factory<typename Type::factory_interface>> make_factory(Args &&... args)
{
return detail::abs_factory<Type, typename Type::factory_interface>();
return detail::abs_factory<Type, typename Type::factory_interface, typename std::decay<Args>::type...>(std::forward<Args>(args)...);
}
}//end namespace pat
}//end namespace nana

View File

@@ -1,7 +1,7 @@
/*
* A Generic Cloneable Pattern Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 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
@@ -106,8 +106,8 @@ namespace nana{ namespace pat{
template<typename T, typename member_enabled<T>::type* = nullptr>
cloneable(T&& t)
: cwrapper_(new detail::cloneable_wrapper<typename std::remove_cv<typename std::remove_reference<T>::type>::type>(std::forward<T>(t)), detail::cloneable_interface_deleter()),
fast_ptr_(reinterpret_cast<typename std::remove_cv<typename std::remove_reference<T>::type>::type*>(cwrapper_->get()))
: cwrapper_(new detail::cloneable_wrapper<typename std::decay<T>::type>(std::forward<T>(t)), detail::cloneable_interface_deleter()),
fast_ptr_(reinterpret_cast<typename std::decay<T>::type*>(cwrapper_->get()))
{}
cloneable(const cloneable& r)