Merge branch 'hotfix-1.7.1' into develop

This commit is contained in:
Jinhao 2019-05-16 23:23:11 +08:00
commit a21d58a5fe
8 changed files with 70 additions and 54 deletions

View File

@ -1,7 +1,7 @@
/**
* A Bedrock Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@ -43,6 +43,20 @@ namespace detail
class flag_guard;
/// RAII class for window message processing
class root_guard
{
public:
/// Enables lazy_update
root_guard(bedrock& brock, basic_window* root_wd);
/// Disables lazy-update and clears update requesters queue.
~root_guard();
private:
bedrock& brock_;
basic_window* const root_wd_;
};
~bedrock();
void pump_event(window, bool is_modal);
void flush_surface(core_window_t*, bool forced, const rectangle* update_area = nullptr);

View File

@ -117,6 +117,7 @@ namespace detail
void map(core_window_t*, bool forced, const rectangle* update_area = nullptr);
bool update(core_window_t*, bool redraw, bool force, const rectangle* update_area = nullptr);
void update_requesters(core_window_t* root_wd);
void refresh_tree(core_window_t*);
void do_lazy_refresh(core_window_t*, bool force_copy_to_screen, bool refresh_tree = false);

View File

@ -1571,7 +1571,7 @@ the nana::detail::basic_window member pointer scheme
* @param img_collapsed An icon displayed in front of category title when the category is collapsed.
* @return the reference of *this.
*/
listbox& category_icon(const paint::image& img_expanded, const paint::image&& img_collapsed);
listbox& category_icon(const paint::image& img_expanded, const paint::image& img_collapsed);
/// Returns first visible element
/**

View File

@ -91,9 +91,26 @@ namespace nana
private:
bedrock *const brock_;
core_window_t *const wd_;
};
//class root_guard
bedrock::root_guard::root_guard(bedrock& brock, basic_window* root_wd):
brock_(brock),
root_wd_(root_wd)
{
root_wd_->other.attribute.root->lazy_update = true;
}
bedrock::root_guard::~root_guard()
{
if (!brock_.wd_manager().available(root_wd_))
return;
root_wd_->other.attribute.root->lazy_update = false;
root_wd_->other.attribute.root->update_requesters.clear();
}
//end class root_guard
bedrock::core_window_t* bedrock::focus()
{
auto wd = wd_manager().root(native_interface::get_focus_window());

View File

@ -556,6 +556,7 @@ namespace detail
context.is_alt_pressed = false;
}
#if 0
class window_proc_guard
{
public:
@ -576,6 +577,7 @@ namespace detail
private:
detail::basic_window* const root_wd_;
};
#endif
void window_proc_for_xevent(Display* /*display*/, XEvent& xevent)
{
@ -593,7 +595,8 @@ namespace detail
{
auto const root_wd = root_runtime->window;
auto msgwnd = root_wd;
window_proc_guard wp_guard{ root_wd };
detail::bedrock::root_guard rw_guard{ brock, root_wd };
auto& context = *brock.get_thread_context(msgwnd->thread_id);
@ -1215,14 +1218,8 @@ namespace detail
}
}
if (wd_manager.available(root_wd) && root_wd->other.attribute.root->update_requesters.size())
{
for (auto wd : root_wd->other.attribute.root->update_requesters)
{
window_layout::paint(wd, window_layout::paint_operation::have_refreshed, false);
wd_manager.map(wd, true);
}
}
wd_manager.update_requesters(root_wd);
root_runtime = wd_manager.root_runtime(native_window);
if(root_runtime)

View File

@ -740,27 +740,6 @@ namespace detail
return static_cast<wchar_t>(vkey);
}
class window_proc_guard
{
public:
window_proc_guard(detail::basic_window* wd) :
root_wd_(wd)
{
root_wd_->other.attribute.root->lazy_update = true;
}
~window_proc_guard()
{
if (!bedrock::instance().wd_manager().available(root_wd_))
return;
root_wd_->other.attribute.root->lazy_update = false;
root_wd_->other.attribute.root->update_requesters.clear();
}
private:
detail::basic_window* const root_wd_;
};
LRESULT CALLBACK Bedrock_WIN32_WindowProc(HWND root_window, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT window_proc_value = 0;
@ -793,7 +772,7 @@ namespace detail
auto const root_wd = root_runtime->window;
auto msgwnd = root_wd;
window_proc_guard wp_guard{ root_wd };
detail::bedrock::root_guard rw_guard{ brock, root_wd };
switch (message)
{
@ -1577,14 +1556,7 @@ namespace detail
def_window_proc = true;
}
if (wd_manager.available(root_wd) && root_wd->other.attribute.root->update_requesters.size())
{
for (auto wd : root_wd->other.attribute.root->update_requesters)
{
window_layout::paint(wd, window_layout::paint_operation::have_refreshed, false);
wd_manager.map(wd, true);
}
}
wd_manager.update_requesters(root_wd);
root_runtime = wd_manager.root_runtime(native_window);
if(root_runtime)

View File

@ -1051,6 +1051,29 @@ namespace detail
return true;
}
void window_manager::update_requesters(core_window_t* root_wd)
{
//Thread-Safe Required!
std::lock_guard<mutex_type> lock(mutex_);
if (this->available(root_wd) && root_wd->other.attribute.root->update_requesters.size())
{
for (auto wd : root_wd->other.attribute.root->update_requesters)
{
using paint_operation = window_layer::paint_operation;
if (!this->available(wd))
continue;
//#431
//Redraws the widget when it has beground effect.
//Because the widget just redraw if it didn't have bground effect when it was inserted to the update_requesters queue
window_layer::paint(wd, (wd->effect.bground ? paint_operation::try_refresh : paint_operation::have_refreshed), false);
this->map(wd, true);
}
}
}
void window_manager::refresh_tree(core_window_t* wd)
{
//Thread-Safe Required!

View File

@ -1199,23 +1199,15 @@ namespace nana
return{};
}
/// return a ref to the real item object at display!!! position pos using current sorting only if it is active, and at absolute position if no sorting is currently active.
/// return a ref to the real item object at display position
category_t::container::value_type& at(const index_pair& pos)
{
auto acc_pos = pos.item;
if (npos != sort_attrs_.column)
acc_pos = index_cast(pos, true).item; //convert display position to absolute position
return get(pos.cat)->items.at(acc_pos);
return get(pos.cat)->items.at(index_cast(pos, true).item);
}
const category_t::container::value_type& at(const index_pair& pos) const
{
auto acc_pos = pos.item;
if (npos != sort_attrs_.column)
acc_pos = index_cast(pos, true).item; //convert display position to absolute position
return get(pos.cat)->items.at(acc_pos);
return get(pos.cat)->items.at(index_cast(pos, true).item);
}
std::vector<cell> at_model(const index_pair& pos) const
@ -6043,7 +6035,7 @@ namespace nana
return *this;
}
listbox& listbox::category_icon(const paint::image& img_expanded, const paint::image&& img_collapsed)
listbox& listbox::category_icon(const paint::image& img_expanded, const paint::image& img_collapsed)
{
internal_scope_guard lock;
_m_ess().ctg_icon_renderer = [img_expanded, img_collapsed](paint::graphics& graph, const rectangle& rt_icon, bool expanded)