[Sofaswitch-svn] [commit] r423 - sofaswitch/trunk/callflow/src
Author: derek Date: Wed Jun 18 23:46:07 2008 New Revision: 423 Modified: sofaswitch/trunk/callflow/src/callflow.cpp sofaswitch/trunk/callflow/src/callflow.h sofaswitch/trunk/callflow/src/canvas.cpp sofaswitch/trunk/callflow/src/canvas.h Log: Work hard to get keyboard events to be detected. They refuse to be detected.ARRRGGGH. Modified: sofaswitch/trunk/callflow/src/callflow.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/callflow.cpp (original) +++ sofaswitch/trunk/callflow/src/callflow.cpp Wed Jun 18 23:46:07 2008 @@ -116,7 +116,8 @@ EVT_MENU ( wxH_FILESAVE__AS, MyFrame::OnFileSave__As) EVT_MENU ( wxH_HELPABOUT, MyFrame::OnHelpAbout) EVT_MENU ( wxH_HELPMANUAL, MyFrame::OnHelpManual) - EVT_CHAR_HOOK(MyFrame::OnKeyDown) + EVT_CHAR_HOOK(MyFrame::OnAnyKeyDown) + EVT_KEY_DOWN(MyFrame::OnAnyKeyDown) EVT_CLOSE(MyFrame::OnClose) END_EVENT_TABLE() @@ -142,6 +143,12 @@ MyFrame *frame = new MyFrame (wxT("Callflow"), wxPoint(20,20), wxSize(600,450)); + frame->PushEventHandler(new FrameKeyEvtHandler(*frame)); + + frame->Connect(wxID_ANY, + wxEVT_KEY_DOWN, + wxKeyEventHandler(MyFrame::OnKeyDown), + NULL, this); frame->Show (TRUE); ::wxInitAllImageHandlers(); @@ -229,9 +236,9 @@ SetSize(1100, 700); } -void MyFrame::OnKeyDown(wxKeyEvent & event) +void MyFrame::OnAnyKeyDown(wxKeyEvent & event) { - canvas->HandleKeyDown(event); + canvas->OnKeyDown(event); } void MyFrame::OnClose (wxCloseEvent& event) @@ -701,6 +708,24 @@ } +///////////////////////////////////////////////////////////////////////////// + +FrameKeyEvtHandler::FrameKeyEvtHandler(MyFrame &_myFrame) +: myFrame(_myFrame) +{ +} + +void FrameKeyEvtHandler::OnKeyDown(wxKeyEvent & event) +{ + myFrame.OnKeyDown(event); +} + +BEGIN_EVENT_TABLE(FrameKeyEvtHandler, wxEvtHandler) +EVT_KEY_DOWN(FrameKeyEvtHandler::OnKeyDown) +END_EVENT_TABLE(); + + + /* The comment below is magic for those who use emacs to edit this file. With * the comment below, the tab key does auto indent to 4 spaces. * Modified: sofaswitch/trunk/callflow/src/callflow.h ============================================================================== --- sofaswitch/trunk/callflow/src/callflow.h (original) +++ sofaswitch/trunk/callflow/src/callflow.h Wed Jun 18 23:46:07 2008 @@ -83,11 +83,14 @@ /**Destructor */ ~MyFrame (); - protected: /**Process event - character read from the keyboard when the key is pressed */ - void OnKeyDown(wxKeyEvent & event); + void OnKeyDown(wxKeyEvent & event) { OnAnyKeyDown(event); } + protected: + /**Process event - character read from the keyboard when the key + is pressed */ + void OnAnyKeyDown(wxKeyEvent & event); public: /**Called in response to a shutdown command issued from somewhere */ @@ -315,6 +318,33 @@ }; + +///////////////////////////////////////////////////////////////////////////// + + +class FrameKeyEvtHandler : public wxEvtHandler +{ +public: + /**Constructor */ + FrameKeyEvtHandler(MyFrame & _myFrame); + + /**Destructor */ + ~FrameKeyEvtHandler() { } + + /**The key down event goes here */ + void OnKeyDown(wxKeyEvent & event); + +private: + /**Reference back to the class that has to collect the event */ + MyFrame & myFrame; + + /**Make WxWidgets happy, use this macro, which means we collect + key events in this class */ + DECLARE_EVENT_TABLE() +}; + + + #endif Modified: sofaswitch/trunk/callflow/src/canvas.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/canvas.cpp (original) +++ sofaswitch/trunk/callflow/src/canvas.cpp Wed Jun 18 23:46:07 2008 @@ -39,6 +39,7 @@ EVT_ENTER_WINDOW (MyCanvas::OnMouseEnter) EVT_LEAVE_WINDOW (MyCanvas::OnMouseLeave) EVT_CHAR_HOOK (MyCanvas::OnKeyDown) + EVT_KEY_DOWN (MyCanvas::OnKeyDown) EVT_TIMER (TimerId, MyCanvas::OnProgressTimer) END_EVENT_TABLE () @@ -52,6 +53,10 @@ timerActivity = new wxTimer (this, TimerId); timerActivity->Start (500); + Connect(wxID_ANY, + wxEVT_KEY_DOWN, + wxKeyEventHandler(MyCanvas::OnKeyDown), + NULL, this); } @@ -651,7 +656,7 @@ void KeyEvtHandler::OnKeyDown(wxKeyEvent & event) { - myCanvas.HandleKeyDown(event); + myCanvas.OnKeyDown(event); } BEGIN_EVENT_TABLE(KeyEvtHandler, wxEvtHandler) Modified: sofaswitch/trunk/callflow/src/canvas.h ============================================================================== --- sofaswitch/trunk/callflow/src/canvas.h (original) +++ sofaswitch/trunk/callflow/src/canvas.h Wed Jun 18 23:46:07 2008 @@ -25,10 +25,9 @@ /**Destroy this canvas, which is called by the system on close down */ ~MyCanvas (); - - /**Alllow the onKeyDown method to be called... */ - void HandleKeyDown(wxKeyEvent & event) - { OnKeyDown(event); } + /**Process event - character read from the keyboard when the key + is pressed */ + void OnKeyDown(wxKeyEvent & event); /**Process event - left mouse button has been pressed */ void OnLeftDown (wxMouseEvent & event); @@ -128,9 +127,6 @@ DECLARE_EVENT_TABLE(); protected: - /**Process event - character read from the keyboard when the key - is pressed */ - void OnKeyDown(wxKeyEvent & event); /**Given a mouse event at some location, what is the correct (in this canvas view point) location of this event? This method @@ -211,10 +207,6 @@ - - - - #endif
participants (1)
-
SofaSWITCH SVN