diff --git a/include/nana/gui/detail/basic_window.hpp b/include/nana/gui/detail/basic_window.hpp index 659f4316..5534e738 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/include/nana/gui/detail/basic_window.hpp @@ -21,7 +21,7 @@ #include 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; diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index c2430ccd..57765e76 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -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 diff --git a/source/gui/detail/basic_window.cpp b/source/gui/detail/basic_window.cpp index 96aec1fa..16889dff 100644 --- a/source/gui/detail/basic_window.cpp +++ b/source/gui/detail/basic_window.cpp @@ -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; diff --git a/source/gui/detail/linux_X11/bedrock.cpp b/source/gui/detail/linux_X11/bedrock.cpp index 44ccef61..d6ad0255 100644 --- a/source/gui/detail/linux_X11/bedrock.cpp +++ b/source/gui/detail/linux_X11/bedrock.cpp @@ -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) diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/win32/bedrock.cpp index 4a9d0f11..1e44cb4e 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/win32/bedrock.cpp @@ -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 diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index b7719985..8188a1cb 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -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(); diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index d6f8b483..b4238fbd 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -1284,5 +1284,25 @@ namespace API } return nana::element_state::normal; } + + bool ignore_mouse_focus(window wd, bool ignore) + { + auto iwd = reinterpret_cast(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(wd); + internal_scope_guard lock; + return (restrict::window_manager.available(iwd) ? iwd->flags.ignore_mouse_focus : false); + } }//end namespace API }//end namespace nana diff --git a/source/gui/widgets/form.cpp b/source/gui/widgets/form.cpp index 0c8cfc43..eab587ad 100644 --- a/source/gui/widgets/form.cpp +++ b/source/gui/widgets/form.cpp @@ -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) diff --git a/source/gui/widgets/panel.cpp b/source/gui/widgets/panel.cpp index d360d916..8b09f6f0 100644 --- a/source/gui/widgets/panel.cpp +++ b/source/gui/widgets/panel.cpp @@ -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)