fix caret issue

This commit is contained in:
Jinhao 2017-11-02 16:36:23 +08:00
parent 0796c1540b
commit 74f5a8f40b
5 changed files with 26 additions and 17 deletions

View File

@ -273,6 +273,7 @@ that return a corresponding nana::appearance with predefined values.
public:
virtual ~caret_interface() = default;
virtual bool activated() const = 0;
virtual void disable_throw() noexcept = 0;
virtual void effective_range(const rectangle& range) = 0;

View File

@ -55,6 +55,7 @@ namespace detail
void dimension(const size& s) override;
void visible(bool visibility) override;
bool visible() const override;
bool activated() const override;
private:
basic_window * owner_;
point position_;

View File

@ -204,6 +204,11 @@ namespace nana
{
return (visible_state::invisible != visibility_);
}
bool caret::activated() const
{
return (visible_state::displayed == visibility_);
}
//end class caret
//struct basic_window
@ -329,24 +334,18 @@ namespace nana
return false;
}
const basic_window* get_child_caret(const basic_window* wd, bool this_is_a_child)
{
if (this_is_a_child && wd->annex.caret_ptr)
return wd;
for (auto child : wd->children)
{
auto caret_wd = get_child_caret(child, true);
if (caret_wd)
return caret_wd;
}
return nullptr;
}
const basic_window * basic_window::child_caret() const
{
return get_child_caret(this, false);
for (auto child : children) {
//Only return the child who has activated caret.
if (child->annex.caret_ptr && child->annex.caret_ptr->activated())
return child;
auto caret = child->child_caret();
if (caret)
return caret;
}
return nullptr;
}
bool basic_window::is_draw_through() const

View File

@ -151,7 +151,8 @@ namespace nana
arg.window_handle = reinterpret_cast<window>(wd);
if (emit(event_code::expose, wd, arg, false, get_thread_context()))
{
const core_window_t * caret_wd = (wd->annex.caret_ptr ? wd : wd->child_caret());
//Get the window who has the activated caret
const core_window_t * caret_wd = ((wd->annex.caret_ptr && wd->annex.caret_ptr->activated()) ? wd : wd->child_caret());
if (caret_wd)
{
if (exposed)

View File

@ -1183,6 +1183,13 @@ namespace API
auto caret = _m_caret();
return (caret && caret->visible());
}
bool activated() const override
{
internal_scope_guard lock;
auto caret = _m_caret();
return (caret && caret->activated());
}
private:
caret_interface* _m_caret() const
{