Commit by : luke
Repository : xara
Revision : 980
Date : Tue May 9 13:43:59 BST 2006
Changed paths:
M /Trunk/XaraLX/wxOil/camelot.cpp
M /Trunk/XaraLX/wxOil/camelot.h
M /Trunk/XaraLX/wxOil/keypress.cpp
M /Trunk/XaraLX/wxOil/rendwnd.cpp
Key handling fixes
Diff:
Index: Trunk/XaraLX/wxOil/rendwnd.cpp
===================================================================
--- Trunk/XaraLX/wxOil/rendwnd.cpp (revision 979)
+++ Trunk/XaraLX/wxOil/rendwnd.cpp (revision 980)
@@ -375,12 +375,12 @@
/*********************************************************************************************
> void CRenderWnd::OnKey( wxKeyEvent & event )
- Author: Luke_Hart <lukeh@xxxxxxxx>
- Created: 7 May 2006
+ Author: Alex Bligh (alex@xxxxxxxxxxx)
+ Created: 2 May 2006
Inputs: reference to the event
Outputs: -
Returns: -
- Purpose: This now the main keypress handling function. It also notes a key has been
+ Purpose: This DOES NOT ACTUALLY HANDLE EVENTS, it only notes a key has been
pressed and stops the mouse motion mangler eating the next mouse move.
Errors: -
Scope: Protected
@@ -390,20 +390,9 @@
void CRenderWnd::OnKey( wxKeyEvent & event )
{
- // This is Alex Blighs (alex@xxxxxxxxxxx) mouse skip inhibition code
if (m_pView)
m_pView->DontSkipNextMouse();
- // Make sure the kernel knows which view/doc the event applies to, if any.
- if( NULL != Document::GetSelected() )
- Document::GetSelected()->SetCurrent();
- if( NULL != DocView::GetSelected() )
- DocView::GetSelected()->SetCurrent();
-
- // Process keyboard messages
- if( !CCamFrame::GetMainFrame()->IsIconized() && KeyPress::TranslateMessage( &event ) )
- return;
-
event.Skip(); // Pass the key event on to someone who really wants it.
}
Index: Trunk/XaraLX/wxOil/camelot.h
===================================================================
--- Trunk/XaraLX/wxOil/camelot.h (revision 979)
+++ Trunk/XaraLX/wxOil/camelot.h (revision 980)
@@ -139,6 +139,8 @@
void OnTimer ( wxTimerEvent &event );
void GiveActiveCanvasFocus();
+
+ int FilterEvent( wxEvent& event );
protected:
std::auto_ptr<wxDocManager> m_docManager;
Index: Trunk/XaraLX/wxOil/camelot.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camelot.cpp (revision 979)
+++ Trunk/XaraLX/wxOil/camelot.cpp (revision 980)
@@ -119,6 +119,7 @@
#include "cversion.h"
#include "camelot.h"
+#include "keypress.h"
#include "ccdc.h"
#include "camprofile.h"
#include "dlgevt.h"
@@ -209,12 +210,96 @@
{
}
+int CCamApp::FilterEvent( wxEvent& event )
+{
+ if( event.GetEventType() == wxEVT_KEY_DOWN ||
+ event.GetEventType() == wxEVT_KEY_UP )
+ {
+ wxObject* pEventObject = event.GetEventObject();
+ TRACEUSER( "jlh92", _T("KeyEvent 4 %s %s
"),
+ ((wxWindow*)pEventObject)->GetClassInfo()->GetClassName(),
+ event.GetEventType() == wxEVT_KEY_DOWN ? _T("KD") : _T("KU") );
+
+ // Is the object allowed to recieve keys?
+ wxClassInfo* pClassInfo = pEventObject->GetClassInfo();
+ if( pClassInfo->IsKindOf( CLASSINFO(wxTextCtrl) ) ||
+ pClassInfo->IsKindOf( CLASSINFO(wxComboBox) ) )
+ {
+ TRACEUSER( "jlh92", _T("Control gets keys") );
+ // Yes, pass on as usual
+ return -1;
+ }
+
+ // Scan down ancestors looking for either wxPanels (always non-modal) and
+ // wxDailogs (can be modal, so we check)
+ wxWindow *pWnd = (wxWindow*)pEventObject;
+ while( NULL != pWnd && !pWnd->IsKindOf( CLASSINFO(wxPanel) ) )
+ {
+ // Dialogs may-be modal so check
+ if( pWnd->IsKindOf( CLASSINFO(wxDialog) ) )
+ {
+ // Pass event down chain if modal
+ if( ((wxDialog*)pWnd)->IsModal() )
+ {
+ TRACEUSER( "jlh92", _T("Modal dialog
") );
+ return -1;
+ }
+
+ // Non-modal dialog so do focus handling
+ break;
+ }
+
+ pWnd = pWnd->GetParent();
+ }
+
+ // Make sure the kernel knows which view/doc the event applies to, if any.
+ if( NULL != Document::GetSelected() )
+ Document::GetSelected()->SetCurrent();
+ if( NULL != DocView::GetSelected() )
+ DocView::GetSelected()->SetCurrent();
+
+ TRACEUSER( "jlh92", _T("Handled!
") );
+
+ // Process keyboard messages (and mark event as handled)
+ if( !CCamFrame::GetMainFrame()->IsIconized() && KeyPress::TranslateMessage( (wxKeyEvent*)&event ) )
+ return true;
+ }
+
+ return -1;
+}
+
/***************************************************************************************************************************/
//
// Initialisation.
//
+static bool GiveFocusToFocusableOffspring( wxWindow* pWnd )
+{
+ TRACEUSER( "jlh92", _T("GF2FO class %s
"), pWnd->GetClassInfo()->GetClassName() );
+ // Can we give focus to passed window. Yes, give focus
+ // and return happy
+ if( pWnd->AcceptsFocus() )
+ {
+ TRACEUSER( "jlh92", _T("Focused!
") );
+ pWnd->SetFocus();
+ return true;
+ }
+
+ // No, lets try the children then
+ wxWindowList& lstChild = pWnd->GetChildren();
+ wxWindowListNode* pNode = lstChild.GetFirst();
+ while( NULL != pNode )
+ {
+ if( GiveFocusToFocusableOffspring( pNode->GetData() ) )
+ return true;
+
+ pNode = pNode->GetNext();
+ }
+
+ return false;
+}
+
bool CCamApp::OnInit()
{
//
@@ -314,7 +399,7 @@
// Useful debug tracing enablers, left here for next debug session...
// wxLog::AddTraceMask( _T("focus") );
- wxLog::AddTraceMask( _T("keyevent") );
+// wxLog::AddTraceMask( _T("keyevent") );
// Initialise the MonotonicTime class
MonotonicTime::Init();
@@ -533,10 +618,9 @@
// Remove the splash screen
CamResource::DoneInit();
- // Give focus to second child (status bar), parent can't have it since
+ // Give focus to any child that will take it, parent can't have it since
// it's a frame (see gtk_widget_grab_focus)
- if( NULL != m_pMainFrame->GetStatusBar() )
- m_pMainFrame->GetStatusBar()->SetFocus();
+ GiveFocusToFocusableOffspring( m_pMainFrame );
// Create timer used for background rendering.
// m_Timer.SetOwner(this,CAM_TIMER_ID);
Index: Trunk/XaraLX/wxOil/keypress.cpp
===================================================================
--- Trunk/XaraLX/wxOil/keypress.cpp (revision 979)
+++ Trunk/XaraLX/wxOil/keypress.cpp (revision 980)
@@ -332,7 +332,7 @@
#endif
#endif
// Update the last virtual keycode if not a modifier
- switch( m_LastVirtKey )
+ switch( VirtKey )
{
case WXK_SHIFT:
case WXK_ALT:
Xara