diff --git a/src/gui/util.cpp b/src/gui/util.cpp index 6b17d51e..b068675e 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -33,6 +33,53 @@ int focused_control(const Window* window) { } } +void set_status_text(Window* wnd, const String& s) { + while (wnd) { + wxFrame* f = dynamic_cast(wnd); + if (f) { + f->SetStatusText(s); + return; + } + wnd = wnd->GetParent(); + } +} + + +struct StoredStatusString : public wxClientData { + String s; +}; + +// Don't use this! +struct FakeWindowClass : public wxWindow { + void onControlEnter(wxMouseEvent& ev) { + wxWindow* wnd = (wxWindow*)ev.GetEventObject(); + if (wnd) { + StoredStatusString* d = static_cast(wnd->GetClientObject()); + set_status_text(wnd, d->s); + } + ev.Skip(); + } + void onControlLeave(wxMouseEvent& ev) { + set_status_text((wxWindow*)ev.GetEventObject(), wxEmptyString); + ev.Skip(); + } +}; + +void set_help_text(Window* wnd, const String& s) { + StoredStatusString* d = static_cast(wnd->GetClientObject()); + if (d) { + // already called before + } else { + // first time + d = new StoredStatusString; + wnd->SetClientObject(d); + wnd->Connect(wxEVT_ENTER_WINDOW,wxMouseEventHandler(FakeWindowClass::onControlEnter),wnd,nullptr); + wnd->Connect(wxEVT_LEAVE_WINDOW,wxMouseEventHandler(FakeWindowClass::onControlLeave),wnd,nullptr); + } + d->s = s; +} + + // ----------------------------------------------------------------------------- : DC related /// Fill a DC with a single color diff --git a/src/gui/util.hpp b/src/gui/util.hpp index 0cfe2d3a..dc60e09a 100644 --- a/src/gui/util.hpp +++ b/src/gui/util.hpp @@ -23,6 +23,12 @@ class RealRect; /// Id of the control that has the focus in the given window, or -1 if no control has the focus int focused_control(const Window* window); +/// (Try to) set the status text of a parent of window +void set_status_text(Window* window, const String& text); + +/// Set the help text for a window, it will be shown in the status bar on mouse over +void set_help_text(Window* window, const String& text); + // ----------------------------------------------------------------------------- : DC related /// Fill a DC with a single color