API::tabstop(window) enables a window to receive a tab stop. So how do you disable it? i.e. a TAB key will not move to that window!

API::tabstop(window) enables a window to receive a tab stop. So how do you disable it? i.e. a TAB key will not move to that window!

That's a good question. I don't know if there's a "built-in" way to do it, but it's possible to program the behavior:

wdg.events().focus([&](const nana::arg_focus &arg)
{
    if(arg.getting && arg.focus_reason == nana::arg_focus::reason::tabstop)
        nana::API::move_tabstop(wdg, true);
});

There should be a library-provided way to skip a tabstop, otherwise what's the point of API::tabstop(window)? Maybe someone more knowledgeable can clarify.

That's a good question. I don't know if there's a "built-in" way to do it, but it's possible to program the behavior: ```` wdg.events().focus([&](const nana::arg_focus &arg) { if(arg.getting && arg.focus_reason == nana::arg_focus::reason::tabstop) nana::API::move_tabstop(wdg, true); }); ```` There should be a library-provided way to skip a tabstop, otherwise what's the point of `API::tabstop(window)`? Maybe someone more knowledgeable can clarify.

That's what I got too. But then, problem arises when someone press Shift+Tab from the next control.... and the focus will stay still.... on that control....

That's what I got too. But then, problem arises when someone press Shift+Tab from the next control.... and the focus will stay still.... on that control....

That's what I got too. But then, problem arises when someone press Shift+Tab from the next control.... and the focus will stay still.... on that control....

I hadn't considered that possibility, and I don't think there's a simple way to account for it. That doesn't mean it can't be done, though. I got a little carried away, and came up with this:

// nana::form fm;
std::vector<nana::window> widgets; // the handles of all the widgets in the form, in the order they were added
nana::window wdg_no_tabstop {the_widget_to_exclude}; // the handle of the widget for which the tabstop should be skipped

// this event handler will be registered with every widget in the form
auto focus_handler = [&](const nana::arg_focus &arg)
{
    static nana::window from {nullptr}; // the handle of the widget from which the focus moved to this widget

    if(arg.getting && arg.window_handle == wdg_no_tabstop)
    {
        if(arg.focus_reason == nana::arg_focus::reason::tabstop)
        {
            auto it_this {std::find(widgets.begin(), widgets.end(), arg.window_handle)};
            if(it_this != widgets.end())
            {
                if(!from) // if no widget was previously focused
                {
                    nana::API::move_tabstop(arg.window_handle, true); // move the focus forward
                    return;
                }

                auto it_from {std::find(widgets.begin(), widgets.end(), from)};

                if(it_from < it_this) // if the focus came from behind this widget
                {
                    // if this widget is the last, and the focus came from the first widget
                    if(*it_this == *widgets.rbegin() && it_from == widgets.begin())
                        nana::API::move_tabstop(arg.window_handle, false); // move the focus backward
                    else nana::API::move_tabstop(arg.window_handle, true); // otherwise, move the focus forward
                }
                else // the focus came from ahead
                {
                    // if this widget is the first, and the focus came from the last widget
                    if(it_this == widgets.begin() && *it_from == *widgets.rbegin())
                        nana::API::move_tabstop(arg.window_handle, true); // move the focus forward
                    else nana::API::move_tabstop(arg.window_handle, false); // otherwise, move the focus backward
                }
            }
        }
    }
    else
    {
        from = arg.window_handle;
    }
};

// enumerate widgets non-recursively (I haven't considered what happens if it's done recursively)
nana::API::enum_widgets(fm, false, [&](nana::widget &wdg)
{
    wdg.events().focus(focus_handler);
    widgets.push_back(wdg);
});
>That's what I got too. But then, problem arises when someone press Shift+Tab from the next control.... and the focus will stay still.... on that control.... I hadn't considered that possibility, and I don't think there's a simple way to account for it. That doesn't mean it can't be done, though. I got a little carried away, and came up with this: ```` // nana::form fm; std::vector<nana::window> widgets; // the handles of all the widgets in the form, in the order they were added nana::window wdg_no_tabstop {the_widget_to_exclude}; // the handle of the widget for which the tabstop should be skipped // this event handler will be registered with every widget in the form auto focus_handler = [&](const nana::arg_focus &arg) { static nana::window from {nullptr}; // the handle of the widget from which the focus moved to this widget if(arg.getting && arg.window_handle == wdg_no_tabstop) { if(arg.focus_reason == nana::arg_focus::reason::tabstop) { auto it_this {std::find(widgets.begin(), widgets.end(), arg.window_handle)}; if(it_this != widgets.end()) { if(!from) // if no widget was previously focused { nana::API::move_tabstop(arg.window_handle, true); // move the focus forward return; } auto it_from {std::find(widgets.begin(), widgets.end(), from)}; if(it_from < it_this) // if the focus came from behind this widget { // if this widget is the last, and the focus came from the first widget if(*it_this == *widgets.rbegin() && it_from == widgets.begin()) nana::API::move_tabstop(arg.window_handle, false); // move the focus backward else nana::API::move_tabstop(arg.window_handle, true); // otherwise, move the focus forward } else // the focus came from ahead { // if this widget is the first, and the focus came from the last widget if(it_this == widgets.begin() && *it_from == *widgets.rbegin()) nana::API::move_tabstop(arg.window_handle, true); // move the focus forward else nana::API::move_tabstop(arg.window_handle, false); // otherwise, move the focus backward } } } } else { from = arg.window_handle; } }; // enumerate widgets non-recursively (I haven't considered what happens if it's done recursively) nana::API::enum_widgets(fm, false, [&](nana::widget &wdg) { wdg.events().focus(focus_handler); widgets.push_back(wdg); }); ````
edited Sep 1 at 9:55 pm

Nicely done!!!

enum_widgets should be done recursively because not all widgets have their parent as the form.

Nicely done!!! enum_widgets should be done recursively because not all widgets have their parent as the form.

I have a form class based on nana::form...

Recursively, enum_widgets enumerates all the widget-members on that form... including any form, any nested_form...and all the widgets inside the form members, nested_form members... which is not cool...

There is no way around it. I have to go into source code and add some codes to exclude form/nested_form...

I have a form class based on nana::form... Recursively, enum_widgets enumerates all the widget-members on that form... including any form, any nested_form...and all the widgets inside the form members, nested_form members... which is not cool... There is no way around it. I have to go into source code and add some codes to exclude form/nested_form...

It is better to open an issue in github about improving tab handling. I would create a

taborder map<int tab_order, wd>

instead of the current

vector<wd*>:  wd->root_widget->other.attribute.root->tabstop

And add a new function:

set_tab_order(int order);

if order==0 no stop.

It is better to open an issue in github about improving tab handling. I would create a ```` taborder map<int tab_order, wd> ```` instead of the current ```` vector<wd*>: wd->root_widget->other.attribute.root->tabstop ```` And add a new function: ```` set_tab_order(int order); ```` if order==0 no stop.
38
views
6
replies
3
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft