Make keyboard sample output less confusing.

Warn if key presses occur when the input window doesn't have focus as the
usual key events are not generated then which could be understood as a bug in
the sample instead of the correct result.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72253 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-07-29 22:08:21 +00:00
parent 1043456035
commit c4f49d69cf

View File

@ -54,6 +54,16 @@ private:
void OnChar(wxKeyEvent& event) { LogEvent("Char", event); } void OnChar(wxKeyEvent& event) { LogEvent("Char", event); }
void OnCharHook(wxKeyEvent& event) void OnCharHook(wxKeyEvent& event)
{ {
// The logged messages can be confusing if the input window doesn't
// have focus so warn about this.
if ( !m_inputWin->HasFocus() )
{
m_logText->SetDefaultStyle(*wxRED);
m_logText->AppendText("WARNING: focus is not on input window, "
"non-hook events won't be logged.\n");
m_logText->SetDefaultStyle(wxTextAttr());
}
LogEvent("Hook", event); LogEvent("Hook", event);
if ( m_skipHook ) if ( m_skipHook )
event.Skip(); event.Skip();
@ -167,7 +177,7 @@ MyFrame::MyFrame(const wxString& title)
m_logText = new wxTextCtrl(this, wxID_ANY, "", m_logText = new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL); wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxHSCROLL);
// set monospace font to have output in nice columns // set monospace font to have output in nice columns
wxFont font(10, wxFONTFAMILY_TELETYPE, wxFont font(10, wxFONTFAMILY_TELETYPE,