refine code

fix bug that listbox may throw std::runtime when the modal is enabled
fix bug that textbox attachs a wrong event angent
This commit is contained in:
Jinhao
2016-08-10 01:46:13 +08:00
parent 185a2961d1
commit 6e86b6ae6c
44 changed files with 1120 additions and 1013 deletions

View File

@@ -17,13 +17,11 @@
#ifndef NANA_DETAIL_PLATFORM_SPEC_HPP
#define NANA_DETAIL_PLATFORM_SPEC_HPP
#include <nana/deploy.hpp>
#include <nana/gui/basis.hpp>
#include <nana/paint/image.hpp>
#include <nana/gui/detail/event_code.hpp>
#include <windows.h>
#include <map>
#include <memory>
#include <functional>
@@ -174,6 +172,12 @@ namespace detail
class platform_spec
{
platform_spec();
platform_spec(const platform_spec&) = delete;
platform_spec& operator=(const platform_spec&) = delete;
platform_spec(platform_spec&&) = delete;
platform_spec& operator=(platform_spec&&) = delete;
public:
typedef drawable_impl_type::font_ptr_t font_ptr_t;
typedef ::nana::event_code event_code;
@@ -194,7 +198,7 @@ namespace detail
::nana::paint::image big_icon;
};
platform_spec();
~platform_spec();
const font_ptr_t& default_native_font() const;
void default_native_font(const font_ptr_t&);
@@ -207,8 +211,8 @@ namespace detail
void keep_window_icon(native_window_type, const paint::image&sml_icon, const paint::image& big_icon);
void release_window_icon(native_window_type);
private:
font_ptr_t def_font_ptr_;
std::map<native_window_type, window_icons> iconbase_;
struct implementation;
implementation * const impl_;
};
}//end namespace detail

View File

@@ -1,7 +1,7 @@
/*
* The Store for the Storage Of Elements
* 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
@@ -16,9 +16,7 @@
#include <nana/gui/element.hpp>
#include <nana/pat/cloneable.hpp>
#include <map>
#include <string>
#include <nana/push_ignore_diagnostic>
@@ -28,27 +26,20 @@ namespace detail
{
class element_store
{
typedef ::nana::element::element_interface element_interface;
typedef pat::cloneable< ::nana::element::element_interface> cloneable_element;
using element_interface = ::nana::element::element_interface;
using cloneable_element = pat::cloneable< ::nana::element::element_interface>;
struct data
{
cloneable_element object;
::nana::element::element_interface * fast_ptr;
data();
};
struct store
{
std::map<std::string, data> table;
};
struct data;
public:
element_store();
~element_store();
element_interface * const * bground(const std::string&);
void bground(const std::string&, const pat::cloneable<element_interface>&);
void bground(const std::string&, pat::cloneable<element_interface>&&);
private:
store bground_;
struct implementation;
std::unique_ptr<implementation> impl_;
};
}//end namespace detail
}

View File

@@ -133,10 +133,10 @@ namespace nana{
class root_register
{
public:
root_misc* insert(native_window_type wd, const root_misc& misc)
root_misc* insert(native_window_type wd, root_misc&& misc)
{
recent_ = wd;
auto ret = table_.insert(std::make_pair(wd, misc));
auto ret = table_.emplace(wd, std::move(misc));
misc_ptr_ = &(ret.first->second);
return misc_ptr_;
}

View File

@@ -20,18 +20,11 @@
#include <nana/push_ignore_diagnostic>
#include <vector>
#include "window_layout.hpp"
#include "event_code.hpp"
#include "inner_fwd.hpp"
#include <functional>
#if defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_mutex.hpp>
#else
#include <mutex>
#endif
namespace nana
{
class widget; //forward declaration
@@ -51,15 +44,14 @@ namespace detail
class window_manager
{
class revertible_mutex
: public std::recursive_mutex
{
struct thr_refcnt
{
unsigned tid;
std::size_t refcnt;
};
revertible_mutex(const revertible_mutex&) = delete;
revertible_mutex& operator=(const revertible_mutex&) = delete;
revertible_mutex(revertible_mutex&&) = delete;
revertible_mutex& operator=(revertible_mutex&&) = delete;
public:
revertible_mutex();
~revertible_mutex();
void lock();
bool try_lock();
@@ -68,8 +60,8 @@ namespace detail
void revert();
void forward();
private:
thr_refcnt thr_;
std::vector<thr_refcnt> stack_;
struct implementation;
implementation * const impl_;
};
public:
using native_window = native_window_type;
@@ -90,7 +82,6 @@ namespace detail
bool available(core_window_t*);
bool available(core_window_t *, core_window_t*);
bool available(native_window_type);
core_window_t* create_root(core_window_t*, bool nested, rectangle, const appearance&, widget*);
core_window_t* create_widget(core_window_t*, const rectangle&, bool is_lite, widget*);
@@ -157,7 +148,7 @@ namespace detail
bool calc_window_point(core_window_t*, nana::point&);
root_misc* root_runtime(native_window_type) const;
root_misc* root_runtime(native_window) const;
bool register_shortkey(core_window_t*, unsigned long key);
void unregister_shortkey(core_window_t*, bool with_children);

View File

@@ -16,7 +16,6 @@
#include <nana/paint/graphics.hpp>
#include <nana/pat/cloneable.hpp>
#include <vector>
#include <map>
namespace nana
{
@@ -338,13 +337,8 @@ namespace nana
struct draw_image;
struct draw_graph;
draw_method * method_;
bool vertical_;
nana::rectangle valid_area_;
std::vector<element_state> states_;
std::map<element_state, element_state> join_;
bool stretch_all_;
unsigned left_, top_, right_, bottom_;
struct implementation;
std::unique_ptr<implementation> impl_;
}; //end class bground
}//end namespace element
}//end namespace nana

View File

@@ -17,7 +17,6 @@
#define NANA_GUI_PLACE_HPP
#include <nana/push_ignore_diagnostic>
#include <nana/gui/basis.hpp>
#include <utility>
#include <memory>
#include <functional>

View File

@@ -347,7 +347,8 @@ namespace API
* When you are finished with the caret, be sure to reset the pointer.
*
* @param window_handle A handle to a window whose caret is to be retrieved
* @return a pointer to the caret proxy. nullptr if the window doesn't have a caret.
* @return a pointer to the caret proxy.
* @except throws std::runtime if the window doesn't have a caret when disable_throw is false
*/
::std::unique_ptr<caret_interface> open_caret(window window_handle, bool disable_throw = false);

View File

@@ -720,7 +720,7 @@ namespace nana
class iresolver
{
public:
iresolver(const std::vector<cell>&);
iresolver(std::vector<cell>);
iresolver& operator>>(bool&);
iresolver& operator>>(short&);
@@ -740,7 +740,7 @@ namespace nana
iresolver& operator>>(cell&);
iresolver& operator>>(std::nullptr_t);
private:
const std::vector<cell>& cells_;
std::vector<cell> cells_;
std::size_t pos_{0};
};
@@ -918,7 +918,7 @@ namespace nana
//Undocumented method
essence * _m_ess() const;
private:
std::vector<cell> & _m_cells() const;
std::vector<cell> _m_cells() const;
nana::any * _m_value(bool alloc_if_empty);
const nana::any * _m_value() const;
private:

View File

@@ -17,109 +17,26 @@
#include "textbase.hpp"
#include "text_editor_part.hpp"
#include <nana/gui/widgets/scroll.hpp>
#include <nana/unicode_bidi.hpp>
//#include <nana/paint/graphics.hpp>
#include <nana/gui/detail/general_events.hpp>
#include <functional>
namespace nana
{
namespace paint
{
// Forward declaration
class graphics;
}
}
namespace nana{ namespace widgets
{
namespace skeletons
{
template<typename EnumCommand>
class undoable_command_interface
{
public:
virtual ~undoable_command_interface() = default;
virtual EnumCommand get() const = 0;
virtual bool merge(const undoable_command_interface&) = 0;
virtual void execute(bool redo) = 0;
};
template<typename EnumCommand>
class undoable
{
public:
using command = EnumCommand;
using container = std::deque < std::unique_ptr<undoable_command_interface<command>> >;
void clear()
{
commands_.clear();
pos_ = 0;
}
void max_steps(std::size_t maxs)
{
max_steps_ = maxs;
if (maxs && (commands_.size() >= maxs))
commands_.erase(commands_.begin(), commands_.begin() + (commands_.size() - maxs + 1));
}
std::size_t max_steps() const
{
return max_steps_;
}
void enable(bool enb)
{
enabled_ = enb;
if (!enb)
clear();
}
bool enabled() const
{
return enabled_;
}
void push(std::unique_ptr<undoable_command_interface<command>> && ptr)
{
if (!ptr || !enabled_)
return;
if (pos_ < commands_.size())
commands_.erase(commands_.begin() + pos_, commands_.end());
else if (max_steps_ && (commands_.size() >= max_steps_))
commands_.erase(commands_.begin(), commands_.begin() + (commands_.size() - max_steps_ + 1));
pos_ = commands_.size();
if (!commands_.empty())
{
if (commands_.back().get()->merge(*ptr))
return;
}
commands_.emplace_back(std::move(ptr));
++pos_;
}
std::size_t count(bool is_undo) const
{
return (is_undo ? pos_ : commands_.size() - pos_);
}
void undo()
{
if (pos_ > 0)
{
--pos_;
commands_[pos_].get()->execute(false);
}
}
void redo()
{
if (pos_ != commands_.size())
commands_[pos_++].get()->execute(true);
}
private:
container commands_;
bool enabled_{ true };
std::size_t max_steps_{ 30 };
std::size_t pos_{ 0 };
};
class text_editor
{
struct attributes;
@@ -136,9 +53,14 @@ namespace nana{ namespace widgets
class undo_input_text;
class undo_move_text;
struct keywords;
class keyword_parser;
class helper_pencil;
text_editor(const text_editor&) = delete;
text_editor& operator=(const text_editor&) = delete;
text_editor(text_editor&&) = delete;
text_editor& operator=(text_editor&&) = delete;
public:
using char_type = wchar_t;
using size_type = textbase<char_type>::size_type;
@@ -148,9 +70,10 @@ namespace nana{ namespace widgets
using graph_reference = ::nana::paint::graphics&;
struct ext_renderer_tag
struct renderers
{
std::function<void(graph_reference, const nana::rectangle& text_area, const ::nana::color&)> background;
std::function<void(graph_reference, const nana::rectangle& text_area, const ::nana::color&)> background; ///< a customized background renderer
std::function<void(graph_reference, const ::nana::color&)> border; ///< a customized border renderer
};
enum class accepts
@@ -178,11 +101,10 @@ namespace nana{ namespace widgets
/// Determine whether the text_editor is line wrapped.
bool line_wrapped() const;
/// Set the text_editor whether it is line wrapped, it returns false if the state is not changed.
bool line_wrapped(bool);
void border_renderer(std::function<void(graph_reference, const ::nana::color& bgcolor)>);
bool load(const char*);
/// Sets the text area.
@@ -205,7 +127,7 @@ namespace nana{ namespace widgets
void undo_max_steps(std::size_t);
std::size_t undo_max_steps() const;
ext_renderer_tag& ext_renderer() const;
renderers& customized_renderers();
unsigned line_height() const;
unsigned screen_lines() const;
@@ -267,8 +189,8 @@ namespace nana{ namespace widgets
bool mouse_move(bool left_button, const point& screen_pos);
bool mouse_pressed(const arg_mouse& arg);
skeletons::textbase<wchar_t>& textbase();
const skeletons::textbase<wchar_t>& textbase() const;
skeletons::textbase<char_type>& textbase();
const skeletons::textbase<char_type>& textbase() const;
private:
void _m_pre_calc_lines(std::size_t line_off, std::size_t lines);
@@ -276,7 +198,9 @@ namespace nana{ namespace widgets
::nana::color _m_bgcolor() const;
bool _m_scroll_text(bool vertical);
void _m_scrollbar();
::nana::size _m_text_area() const;
::nana::rectangle _m_text_area() const;
void _m_get_scrollbar_size();
void _m_reset();
::nana::upoint _m_put(::std::wstring);
@@ -295,9 +219,6 @@ namespace nana{ namespace widgets
int _m_text_top_base() const;
/// Returns the right/bottom point of text area.
int _m_end_pos(bool right) const;
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t*, std::size_t len) const;
//_m_draw_string
//@brief: Draw a line of string
@@ -313,47 +234,28 @@ namespace nana{ namespace widgets
unsigned _m_char_by_pixels(const unicode_bidi::entity&, unsigned pos);
unsigned _m_pixels_by_char(const ::std::wstring&, ::std::size_t pos) const;
void _handle_move_key(const arg_keyboard& arg);
void _m_handle_move_key(const arg_keyboard& arg);
void _m_draw_border();
private:
std::unique_ptr<editor_behavior_interface> behavior_;
undoable<command> undo_;
struct implementation;
implementation * const impl_;
nana::window window_;
std::unique_ptr<caret_interface> caret_;
graph_reference graph_;
const text_editor_scheme* scheme_;
event_interface * event_handler_{ nullptr };
std::unique_ptr<keywords> keywords_;
skeletons::textbase<wchar_t> textbase_;
wchar_t mask_char_{0};
mutable ext_renderer_tag ext_renderer_;
std::vector<upoint> text_position_; //position of text from last rendering.
struct indent_rep
{
bool enabled{ false };
std::function<std::string()> generator;
}indent_;
struct attributes
{
accepts acceptive{ accepts::no_restrict };
std::function<bool(char_type)> pred_acceptive;
::std::string tip_string;
bool line_wrapped{false};
bool multi_lines{true};
bool editable{true};
bool enable_background{true};
bool enable_counterpart{false};
nana::paint::graphics counterpart; //this is used to keep the background that painted by external part.
std::unique_ptr<nana::scroll<true>> vscroll;
std::unique_ptr<nana::scroll<false>> hscroll;
}attributes_;
struct text_area_type
@@ -365,7 +267,6 @@ namespace nana{ namespace widgets
unsigned scroll_pixels;
unsigned vscroll;
unsigned hscroll;
std::function<void(nana::paint::graphics&, const ::nana::color&)> border_renderer;
}text_area_;
struct selection

View File

@@ -1,7 +1,7 @@
/**
* A Slider 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
@@ -134,7 +134,7 @@ namespace nana
}//end namespace drawerbase
/// A slider widget wich the user can drag for tracking \todo add scheme ?
/// A slider widget wich the user can drag for tracking
class slider
: public widget_object<category::widget_tag, drawerbase::slider::trigger, drawerbase::slider::slider_events, drawerbase::slider::scheme_impl>
{

View File

@@ -28,14 +28,25 @@ namespace nana
/// Abstract class for defining the capacity interface.
class widget
: nana::noncopyable, nana::nonmovable
{
friend class detail::widget_notifier_interface;
class inner_widget_notifier;
typedef void(*dummy_bool_type)(widget* (*)(const widget&));
//Noncopyable
widget(const widget&) = delete;
widget& operator=(const widget&) = delete;
//Nonmovable
widget(widget&&) = delete;
widget& operator=(widget&&) = delete;
public:
using native_string_type = detail::native_string_type;
widget() = default;
virtual ~widget() = default;
virtual window handle() const = 0; ///< Returns the handle of window, returns 0 if window is not created.
bool empty() const; ///< Determines whether the manipulator is handling a window.
@@ -298,15 +309,8 @@ namespace nana
using event_type = Events;
widget_object()
: widget_object(nullptr, false, API::make_center(300, 150), appearance(), this)
{
handle_ = API::dev::create_window(nullptr, false, API::make_center(300, 150), appearance(), this);
_m_bind_and_attach();
}
widget_object(const rectangle& r, const appearance& apr = {})
{
handle_ = API::dev::create_window(nullptr, false, r, apr, this);
_m_bind_and_attach();
}
widget_object(window owner, bool nested, const rectangle& r = {}, const appearance& apr = {})

View File

@@ -12,7 +12,6 @@
#ifndef NANA_INTERNATIONALIZATION_HPP
#define NANA_INTERNATIONALIZATION_HPP
#include "basic_types.hpp"
#include <vector>
#include <sstream>
#include <functional>
@@ -186,9 +185,7 @@ namespace nana
void _m_add_args(const std::string&);
void _m_add_args(std::string&&);
void _m_add_args(std::wstring&);
void _m_add_args(const std::wstring&);
void _m_add_args(std::wstring&&);
private:
std::string msgid_;
std::vector<std::unique_ptr<eval_arg>> args_;

View File

@@ -1,7 +1,7 @@
/*
* Paint Graphics 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
@@ -17,7 +17,6 @@
#include "../basic_types.hpp"
#include "../gui/basis.hpp"
#include "pixel_buffer.hpp"
namespace nana
{
@@ -72,12 +71,16 @@ namespace nana
class graphics
{
public:
typedef ::nana::native_window_type native_window_type;
graphics();
graphics(const ::nana::size&); ///< size in pixel
graphics(const graphics&); ///< the resource is not copyed, the two graphics objects refer to the *SAME* resource
graphics& operator=(const graphics&);
graphics(graphics&&);
graphics& operator=(graphics&&);
~graphics();
bool changed() const; ///< Returns true if the graphics object is operated
bool empty() const; ///< Returns true if the graphics object does not refer to any resource.
operator const void*() const;
@@ -129,10 +132,10 @@ namespace nana
void flush();
unsigned width() const;
unsigned height() const; ///< Returns the height of the off-screen buffer.
unsigned width() const; ///< Returns the width of the off-screen buffer.
unsigned height() const; ///< Returns the height of the off-screen buffer.
::nana::size size() const;
void setsta(); ///< Clears the status if the graphics object had been changed
void setsta(); ///< Clears the status if the graphics object had been changed
void set_changed();
void release();
@@ -172,12 +175,8 @@ namespace nana
void gradual_rectangle(const ::nana::rectangle&, const color& from, const color& to, bool vertical);
void round_rectangle(const ::nana::rectangle&, unsigned radius_x, unsigned radius_y, const color&, bool solid, const color& color_if_solid);
private:
std::shared_ptr< ::nana::detail::drawable_impl_type> dwptr_;
font font_shadow_;
drawable_type handle_;
::nana::size size_;
pixel_buffer pxbuf_;
bool changed_;
struct implementation;
std::unique_ptr<implementation> impl_;
};
}//end namespace paint
} //end namespace nana