fix a caret issue which happens when parent widget is hidden

This commit is contained in:
Jinhao 2015-06-26 23:59:28 +08:00
parent 1dd61ffb24
commit 8be566214c
6 changed files with 38 additions and 10 deletions

View File

@ -118,9 +118,11 @@ namespace detail
bool is_ancestor_of(const basic_window* wd) const; bool is_ancestor_of(const basic_window* wd) const;
bool visible_parents() const; bool visible_parents() const;
bool displayed() const;
bool belong_to_lazy() const; bool belong_to_lazy() const;
const basic_window * child_caret() const; //Returns a child which owns a caret
bool is_draw_through() const; ///< Determines whether it is a draw-through window. bool is_draw_through() const; // Determines whether it is a draw-through window.
public: public:
//Override event_holder //Override event_holder
bool set_events(const std::shared_ptr<general_events>&) override; bool set_events(const std::shared_ptr<general_events>&) override;

View File

@ -282,6 +282,11 @@ namespace nana
return true; return true;
} }
bool basic_window::displayed() const
{
return (visible && visible_parents());
}
bool basic_window::belong_to_lazy() const bool basic_window::belong_to_lazy() const
{ {
for (auto wd = this; wd; wd = wd->parent) for (auto wd = this; wd; wd = wd->parent)
@ -292,6 +297,26 @@ namespace nana
return false; return false;
} }
const basic_window* get_child_caret(const basic_window* wd, bool this_is_a_child)
{
if (this_is_a_child && wd->together.caret)
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);
}
bool basic_window::is_draw_through() const bool basic_window::is_draw_through() const
{ {
if (::nana::category::flags::root == this->other.category) if (::nana::category::flags::root == this->other.category)

View File

@ -63,15 +63,16 @@ namespace nana
arg.window_handle = reinterpret_cast<window>(wd); arg.window_handle = reinterpret_cast<window>(wd);
if (emit(event_code::expose, wd, arg, false, get_thread_context())) if (emit(event_code::expose, wd, arg, false, get_thread_context()))
{ {
if (wd->together.caret) const core_window_t * caret_wd = (wd->together.caret ? wd : wd->child_caret());
if (caret_wd)
{ {
if (exposed) if (exposed)
{ {
if (wd->root_widget->other.attribute.root->focus == wd) if (wd->root_widget->other.attribute.root->focus == caret_wd)
wd->together.caret->visible(true); caret_wd->together.caret->visible(true);
} }
else else
wd->together.caret->visible(false); caret_wd->together.caret->visible(false);
} }
if (!exposed) if (!exposed)

View File

@ -363,7 +363,7 @@ namespace detail
void bedrock::pump_event(window modal_window, bool is_modal) void bedrock::pump_event(window modal_window, bool is_modal)
{ {
const unsigned tid = ::GetCurrentThreadId(); const unsigned tid = ::GetCurrentThreadId();
thread_context * context = this->open_thread_context(tid); auto context = this->open_thread_context(tid);
if(0 == context->window_count) if(0 == context->window_count)
{ {
//test if there is not a window //test if there is not a window

View File

@ -354,7 +354,7 @@ namespace nana
nana::rectangle r_of_sigwd(sigwd->pos_root, sigwd->dimension); nana::rectangle r_of_sigwd(sigwd->pos_root, sigwd->dimension);
for (auto wd : data_sect.effects_bground_windows) for (auto wd : data_sect.effects_bground_windows)
{ {
if (wd == sigwd || !wd->visible || !wd->visible_parents() || if (wd == sigwd || !wd->displayed() ||
(false == overlap(nana::rectangle{ wd->pos_root, wd->dimension }, r_of_sigwd))) (false == overlap(nana::rectangle{ wd->pos_root, wd->dimension }, r_of_sigwd)))
continue; continue;

View File

@ -698,7 +698,7 @@ namespace detail
std::lock_guard<decltype(mutex_)> lock(mutex_); std::lock_guard<decltype(mutex_)> lock(mutex_);
if (impl_->wd_register.available(wd) == false) return false; if (impl_->wd_register.available(wd) == false) return false;
if (wd->visible && wd->visible_parents()) if (wd->displayed())
{ {
if(forced || (false == wd->belong_to_lazy())) if(forced || (false == wd->belong_to_lazy()))
{ {
@ -722,7 +722,7 @@ namespace detail
std::lock_guard<decltype(mutex_)> lock(mutex_); std::lock_guard<decltype(mutex_)> lock(mutex_);
//It's not worthy to redraw if visible is false //It's not worthy to redraw if visible is false
if (impl_->wd_register.available(wd) && wd->visible && wd->visible_parents()) if (impl_->wd_register.available(wd) && wd->displayed())
window_layer::paint(wd, true, true); window_layer::paint(wd, true, true);
} }
@ -1060,7 +1060,7 @@ namespace detail
bool precondition = false; bool precondition = false;
for (auto & tab_wd : tabs) for (auto & tab_wd : tabs)
{ {
if (tab_wd->visible) if (tab_wd->displayed())
{ {
precondition = true; precondition = true;
break; break;