input widgets keep focus when form/panel is clicked

see API::ignore_mouse_focus
This commit is contained in:
Jinhao 2015-05-17 09:47:58 +08:00
parent e7c9708b4f
commit aac94e238b
9 changed files with 68 additions and 24 deletions

View File

@ -21,7 +21,7 @@
#include <memory>
namespace nana{
class widget; //declaration ofr nana/widgets/widget.hpp
class widget; //declaration of nana/widgets/widget.hpp
namespace detail
{
struct basic_window;
@ -165,9 +165,10 @@ namespace detail
bool dropable :1; //Whether the window has make mouse_drop event.
bool fullscreen :1; //When the window is maximizing whether it fit for fullscreen.
bool borderless :1;
bool make_bground_declared : 1; //explicitly make bground for bground effects
bool ignore_menubar_focus : 1; //A flag indicates whether the menubar sets the focus.
unsigned Reserved :20;
bool make_bground_declared : 1; //explicitly make bground for bground effects
bool ignore_menubar_focus : 1; //A flag indicates whether the menubar sets the focus.
bool ignore_mouse_focus : 1; //A flag indicates whether the widget accepts focus when clicking on it
unsigned Reserved :19;
unsigned char tab; //indicate a window that can receive the keyboard TAB
mouse_action action;
}flags;

View File

@ -300,6 +300,9 @@ namespace API
nana::mouse_action mouse_action(window);
nana::element_state element_state(window);
bool ignore_mouse_focus(window, bool ignore); ///< Enables/disables the mouse focus, it returns the previous state
bool ignore_mouse_focus(window); ///< Determines whether the mouse focus is enabled
}//end namespace API
}//end namespace nana

View File

@ -346,8 +346,9 @@ namespace nana
flags.refreshing = false;
flags.destroying = false;
flags.borderless = false;
flags.make_bground_declared = false;
flags.ignore_menubar_focus = false;
flags.make_bground_declared = false;
flags.ignore_menubar_focus = false;
flags.ignore_mouse_focus = false;
visible = false;

View File

@ -1027,12 +1027,19 @@ namespace detail
{
arg_keyboard argkey;
brock.get_key_state(argkey);
auto the_next = brock.wd_manager.tabstop(msgwnd, !argkey.shift);
if(the_next)
auto tstop_wd = brock.wd_manager.tabstop(msgwnd, argkey.shift);
while (tstop_wd)
{
brock.wd_manager.set_focus(the_next, false);
brock.wd_manager.do_lazy_refresh(the_next, true);
root_runtime->condition.tabstop_focus_changed = true;
if (!tstop_wd->flags.ignore_mouse_focus)
{
brock.wd_manager.set_focus(tstop_wd, false);
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager.do_lazy_refresh(tstop_wd, true);
root_runtime->condition.tabstop_focus_changed = true;
break;
}
tstop_wd = brock.wd_manager.tabstop(tstop_wd, is_forward);
}
}
else if(keyboard::alt == keychar)

View File

@ -935,7 +935,7 @@ namespace detail
{
pressed_wd = msgwnd;
auto new_focus = (msgwnd->flags.take_active ? msgwnd : msgwnd->other.active_window);
if(new_focus)
if(new_focus && (!new_focus->flags.ignore_mouse_focus))
{
auto kill_focus = brock.wd_manager.set_focus(new_focus, false);
if(kill_focus != new_focus)
@ -1393,13 +1393,21 @@ namespace detail
{
if((wParam == 9) && (false == (msgwnd->flags.tab & tab_type::eating))) //Tab
{
auto the_next = brock.wd_manager.tabstop(msgwnd, (::GetKeyState(VK_SHIFT) >= 0));
if(the_next)
bool is_forward = (::GetKeyState(VK_SHIFT) >= 0);
auto tstop_wd = brock.wd_manager.tabstop(msgwnd, is_forward);
while (tstop_wd)
{
brock.wd_manager.set_focus(the_next, false);
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager.do_lazy_refresh(the_next, true);
root_runtime->condition.tabstop_focus_changed = true;
if (!tstop_wd->flags.ignore_mouse_focus)
{
brock.wd_manager.set_focus(tstop_wd, false);
brock.wd_manager.do_lazy_refresh(msgwnd, false);
brock.wd_manager.do_lazy_refresh(tstop_wd, true);
root_runtime->condition.tabstop_focus_changed = true;
break;
}
tstop_wd = brock.wd_manager.tabstop(tstop_wd, is_forward);
}
}
else

View File

@ -1037,7 +1037,7 @@ namespace detail
{
++i;
core_window_t* ts = (i != end ? (*i) : tabs.front());
return (ts != wd ? ts : 0);
return (ts != wd ? ts : nullptr);
}
else
return tabs.front();

View File

@ -1284,5 +1284,25 @@ namespace API
}
return nana::element_state::normal;
}
bool ignore_mouse_focus(window wd, bool ignore)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if (restrict::window_manager.available(iwd))
{
auto state = iwd->flags.ignore_mouse_focus;
iwd->flags.ignore_mouse_focus = ignore;
return state;
}
return false;
}
bool ignore_mouse_focus(window wd)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
return (restrict::window_manager.available(iwd) ? iwd->flags.ignore_mouse_focus : false);
}
}//end namespace API
}//end namespace nana

View File

@ -18,9 +18,10 @@ namespace nana
namespace form
{
//class trigger
void trigger::attached(widget_reference widget, graph_reference graph)
void trigger::attached(widget_reference wdg, graph_reference graph)
{
wd_ = &widget;
wd_ = &wdg;
API::ignore_mouse_focus(wdg, true);
}
void trigger::refresh(graph_reference graph)

View File

@ -20,10 +20,13 @@ namespace nana
namespace panel
{
//class drawer
void drawer::attached(widget_reference widget, graph_reference)
void drawer::attached(widget_reference wdg, graph_reference)
{
widget.caption(STR("Nana Panel"));
window_ = widget.handle();
wdg.caption(STR("panel widget"));
window_ = wdg.handle();
API::ignore_mouse_focus(wdg, true);
}
void drawer::refresh(graph_reference graph)