Project

General

Profile

Track focus changes

Added by Patrik Jeppsson over 3 years ago

Hi,

I want to track focus changes between WDialogs and WApplication::root(). I've

tried to register a listener as such:

WindowManager::WindowManager(CApplication *app) : Wt::WObject(), _d(new WindowManagerPrivate)

{

setObjectName("windowManager");

_d->app = app;

_d->focusInSignal = std::make_unique<Wt::JSignalstd::string>(this, "focusInSignal");

_d~~focusInSignal~~>connect(this, &WindowManager::onFocusIn);

app->doJavaScript("document.addEventListener('focusin', (event) => { Wt.emit('" + id() + "', 'focusInSignal', event.target.id)});");

}

void WindowManager::onFocusIn(const std::string& elementId)

{

std::cout << "Element id: " << elementId << std::endl;

}

It works in the sense that I receive (almost) all the focus changes I expected. However,

I struggle with pairing the elementId with the specific widgets, which is needed to

figure out if e.g. the event target is part of a WDialog. What I want is essentially

a way to get the functionality of WApplication::findWidget(), but based on the id

instead of the widget name.

I would appreciate any ideas on how to solve this issue. Maybe I've tried to tackle it

the wrong way?