Commit 1f291bfc authored by twanvl's avatar twanvl

set_help_text function to add status bar help texts to any window

parent ec72c537
......@@ -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<wxFrame*>(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<StoredStatusString*>(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<StoredStatusString*>(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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment