set_help_text function to add status bar help texts to any window

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1325 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2009-01-10 00:15:06 +00:00
parent ad415f655f
commit 0a26e17de8
2 changed files with 53 additions and 0 deletions
+47
View File
@@ -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