New code for char and key events under GTK 2.0. This

uses the built-in input method which is required
    even for getting European characters. Key down
    events probably don't work anymore. It is still
    impossible to receive Unicode characters due to
    the limitations of wxKeyEvent.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17579 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-10-20 10:15:31 +00:00
parent ba97061f8e
commit cd12eca16a
7 changed files with 431 additions and 63 deletions

View File

@@ -73,9 +73,11 @@ public:
MyCanvas( MyFrame *parent );
void OnPaint( wxPaintEvent &event );
void OnChar( wxKeyEvent &event );
void OnEraseBackground( wxEraseEvent &event );
wxBitmap m_bitmap;
wxString m_text;
private:
DECLARE_EVENT_TABLE()
@@ -160,6 +162,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_PAINT( MyCanvas::OnPaint)
EVT_CHAR( MyCanvas::OnChar)
EVT_ERASE_BACKGROUND( MyCanvas::OnEraseBackground)
END_EVENT_TABLE()
@@ -176,6 +179,22 @@ MyCanvas::MyCanvas( MyFrame *parent )
new wxStaticBitmap( this, -1, m_bitmap, wxPoint(80,20) );
}
void MyCanvas::OnChar( wxKeyEvent &event )
{
// some test cases
switch (event.m_keyCode)
{
case WXK_UP: m_text += wxT( "<UP>" ); break;
case WXK_LEFT: m_text += wxT( "<LEFT>" ); break;
case WXK_RIGHT: m_text += wxT( "<RIGHT>" ); break;
case WXK_DOWN: m_text += wxT( "<DOWN>" ); break;
case WXK_RETURN: m_text += wxT( "<ENTER>" ); break;
default: m_text += event.m_keyCode; break;
}
Refresh();
}
void MyCanvas::OnPaint( wxPaintEvent &event )
{
wxPaintDC dc(this);
@@ -188,6 +207,14 @@ void MyCanvas::OnPaint( wxPaintEvent &event )
dc.SetTextForeground(*wxBLUE);
dc.DrawText(_T("This text is drawn from OnPaint"), 65, 65);
wxString tmp;
tmp.Printf( _T("Hit any key to display more text: %s"), m_text.c_str() );
int w,h;
dc.GetTextExtent( tmp, &w, &h );
dc.SetBrush( *wxWHITE_BRUSH );
dc.DrawRectangle( 65, 85, w, h );
dc.DrawText( tmp, 65, 85 );
#if 0
wxRegionIterator upd( GetUpdateRegion() );