From ec9cd765bc02672383563fd86cad701f375b5ff5 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 29 Aug 2014 16:23:40 -0400 Subject: [PATCH] Fix default menu alt key accelerator bug. (fixes lp:1035151) * Add hot key handled return indicator to DRAW_FRAME::GeneralControl() and DRAW_FRAME::OnHotKey() and all classed derived from DRAW_FRAME. * Add code to all GeneralControl() and OnHotKey() functions to return true if hot key was handled. * Call event skip in DRAW_PANEL::OnKeyEvent() when key event is not handled to allow default menu event handler to function properly. --- common/draw_frame.cpp | 16 +++---- common/draw_panel.cpp | 4 +- cvpcb/class_DisplayFootprintsFrame.cpp | 11 ++++- cvpcb/class_DisplayFootprintsFrame.h | 2 +- eeschema/controle.cpp | 38 +++++++++++------ eeschema/hotkeys.cpp | 27 ++++++------ eeschema/libeditframe.h | 4 +- eeschema/viewlib_frame.h | 2 +- gerbview/controle.cpp | 10 +++-- gerbview/gerbview_frame.h | 4 +- gerbview/hotkeys.cpp | 41 ++++++++++++------ include/draw_frame.h | 10 +++-- include/wxEeschemaStruct.h | 4 +- include/wxPcbStruct.h | 4 +- pagelayout_editor/controle.cpp | 11 +++-- pagelayout_editor/hotkeys.cpp | 20 +++------ pagelayout_editor/pl_editor_frame.h | 4 +- pcbnew/controle.cpp | 11 +++-- pcbnew/footprint_wizard_frame.cpp | 59 ++++++++++++++------------ pcbnew/footprint_wizard_frame.h | 2 +- pcbnew/hotkeys_board_editor.cpp | 25 +++++------ pcbnew/hotkeys_module_editor.cpp | 11 ++--- pcbnew/module_editor_frame.h | 4 +- pcbnew/moduleframe.cpp | 10 +++-- pcbnew/modview_frame.cpp | 11 ++++- pcbnew/modview_frame.h | 2 +- 26 files changed, 206 insertions(+), 141 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 01a1296a51..30aec8332c 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -219,24 +219,17 @@ void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event ) event.Skip(); } -/* function SkipNextLeftButtonReleaseEvent - * after calling this function, if the left mouse button - * is down, the next left mouse button release event will be ignored. - * It is is usefull for instance when closing a dialog on a mouse click, - * to skip the next mouse left button release event - * by the parent window, because the mouse button - * clicked on the dialog is often released in the parent frame, - * and therefore creates a left button released mouse event - * which can be unwanted in some cases - */ + void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() { m_canvas->SetIgnoreLeftButtonReleaseEvent( true ); } + void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) { SetGridVisibility( !IsGridVisible() ); + if( IsGalCanvasActive() ) { GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); @@ -322,8 +315,9 @@ void EDA_DRAW_FRAME::ReCreateMenuBar() } -void EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) +bool EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) { + return false; } diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp index 791ac524dd..15aef15117 100644 --- a/common/draw_panel.cpp +++ b/common/draw_panel.cpp @@ -1389,7 +1389,9 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) ); GetParent()->SetMousePosition( pos ); - GetParent()->GeneralControl( &DC, pos, localkey ); + + if( !GetParent()->GeneralControl( &DC, pos, localkey ) ) + event.Skip(); } diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index 777fec8598..660057f7a1 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -327,13 +327,15 @@ void DISPLAY_FOOTPRINTS_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) } -void DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); @@ -373,12 +375,17 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPositi case ' ': GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; + + default: + eventHandled = false; } SetCrossHairPosition( pos ); RefreshCrossHair( oldpos, aPosition, aDC ); UpdateStatusBar(); /* Display new cursor coordinates */ + + return eventHandled; } diff --git a/cvpcb/class_DisplayFootprintsFrame.h b/cvpcb/class_DisplayFootprintsFrame.h index b26f372565..608081c45c 100644 --- a/cvpcb/class_DisplayFootprintsFrame.h +++ b/cvpcb/class_DisplayFootprintsFrame.h @@ -92,7 +92,7 @@ public: void OnLeftClick( wxDC* DC, const wxPoint& MousePos ); void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ); bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ); - void GeneralControl( wxDC* DC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* DC, const wxPoint& aPosition, int aHotKey = 0 ); void InstallOptionsDisplay( wxCommandEvent& event ); MODULE* Get_Module( const wxString& CmpName ); diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index bbb671eaae..440fed8459 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -203,19 +203,22 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aF } -void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position // ( shift or ctrl key down are PAN command with mouse wheel) bool snapToGrid = true; + if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) snapToGrid = false; @@ -236,28 +239,33 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH SCH_SCREEN* screen = GetScreen(); if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() ) - OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); else - OnHotKey( aDC, aHotKey, aPosition, NULL ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition, NULL ); } UpdateStatusBar(); /* Display cursor coordinates info */ + + return eventHandled; } -void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position // ( shift or ctrl key down are PAN command with mouse wheel) bool snapToGrid = true; + if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) snapToGrid = false; @@ -275,20 +283,24 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( aHotKey ) { - OnHotKey( aDC, aHotKey, aPosition, NULL ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition, NULL ); } UpdateStatusBar(); + + return eventHandled; } -void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } wxPoint pos = aPosition; @@ -304,10 +316,12 @@ void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH SCH_SCREEN* screen = GetScreen(); if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() ) - OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); else - OnHotKey( aDC, aHotKey, aPosition, NULL ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition, NULL ); } - UpdateStatusBar(); /* Display cursor coordinates info */ + UpdateStatusBar(); // Display cursor coordinates info. + + return eventHandled; } diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index b3ec06d534..2847aad2a2 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -319,10 +319,10 @@ struct EDA_HOTKEY_CONFIG s_Viewlib_Hokeys_Descr[] = * Hot keys. Some commands are relative to the item under the mouse cursor * Commands are case insensitive */ -void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) +bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) { if( aHotKey == 0 ) - return; + return false; wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); @@ -354,13 +354,13 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, hotKey = GetDescriptorFromHotkey( aHotKey, s_Schematic_Hotkey_List ); if( hotKey == NULL ) - return; + return false; switch( hotKey->m_Idcommand ) { default: case HK_NOT_FOUND: - return; + return false; case HK_HELP: // Display Current hotkey list DisplayHotkeyList( this, s_Schematic_Hokeys_Descr ); @@ -531,18 +531,16 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, } break; } + + // Hot key handled. + return true; } -/* - * Hot keys for the component editor. Some commands are relatives to the item - * under the mouse cursor - * Commands are case insensitive - */ -void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) +bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) { if( aHotKey == 0 ) - return; + return false; wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); @@ -561,13 +559,13 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, hotKey = GetDescriptorFromHotkey( aHotKey, s_LibEdit_Hotkey_List ); if( hotKey == NULL ) - return; + return false; switch( hotKey->m_Idcommand ) { default: case HK_NOT_FOUND: - return; + return false; case HK_HELP: // Display Current hotkey list DisplayHotkeyList( this, s_Libedit_Hokeys_Descr ); @@ -702,4 +700,7 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, } break; } + + // Hot key handled. + return true; } diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index c904c3c20f..ab85daf329 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -318,9 +318,9 @@ public: double BestZoom(); // Returns the best zoom void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ); - void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); + bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void LoadSettings( wxConfigBase* aCfg ); diff --git a/eeschema/viewlib_frame.h b/eeschema/viewlib_frame.h index 29cbecce2d..36b46351c3 100644 --- a/eeschema/viewlib_frame.h +++ b/eeschema/viewlib_frame.h @@ -87,7 +87,7 @@ public: void ClickOnCmpList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void LoadSettings( wxConfigBase* aCfg ); void SaveSettings( wxConfigBase* aCfg ); diff --git a/gerbview/controle.cpp b/gerbview/controle.cpp index 2bfd01e8d3..ace281c534 100644 --- a/gerbview/controle.cpp +++ b/gerbview/controle.cpp @@ -33,13 +33,15 @@ #include -void GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } wxPoint pos = aPosition; @@ -51,8 +53,10 @@ void GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( aHotKey ) { - OnHotKey( aDC, aHotKey, aPosition ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition ); } UpdateStatusBar(); + + return eventHandled; } diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 20d549dd59..3cead41440 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -511,7 +511,7 @@ public: * @param aPosition The cursor position in logical (drawing) units. * @param aItem = NULL or pointer on a EDA_ITEM under the mouse cursor */ - void OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); + bool OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); GERBER_DRAW_ITEM* GerberGeneralLocateAndDisplay(); GERBER_DRAW_ITEM* Locate( const wxPoint& aPosition, int typeloc ); @@ -621,7 +621,7 @@ public: bool LoadExcellonFiles( const wxString& aFileName ); bool Read_EXCELLON_File( const wxString& aFullFileName ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); /** * Set Size Items (Lines, Flashes) from DCodes List diff --git a/gerbview/hotkeys.cpp b/gerbview/hotkeys.cpp index 76bae66e51..03616cb515 100644 --- a/gerbview/hotkeys.cpp +++ b/gerbview/hotkeys.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2010 + * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + /** * @file gerbview/hotkeys.cpp */ @@ -70,16 +94,7 @@ struct EDA_HOTKEY_CONFIG s_Gerbview_Hokeys_Descr[] = }; -/* - * Function OnHotKey. - * ** Commands are case insensitive ** - * Some commands are relatives to the item under the mouse cursor - * aDC = current device context - * aHotkeyCode = hotkey code (ascii or wxWidget code for special keys) - * aPosition The cursor position in logical (drawing) units. - * aItem = NULL or pointer on a EDA_ITEM under the mouse cursor - */ -void GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem ) +bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem ) { wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); @@ -92,13 +107,13 @@ void GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_Gerbview_Hotkey_List ); if( HK_Descr == NULL ) - return; + return false; switch( HK_Descr->m_Idcommand ) { default: case HK_NOT_FOUND: - return; + return false; case HK_HELP: // Display Current hotkey list DisplayHotkeyList( this, s_Gerbview_Hokeys_Descr ); @@ -162,4 +177,6 @@ void GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit } break; } + + return true; } diff --git a/include/draw_frame.h b/include/draw_frame.h index 829c9317b5..30c3f909c3 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -278,7 +278,8 @@ public: void OnMenuOpen( wxMenuEvent& event ); void OnMouseEvent( wxMouseEvent& event ); - /** function SkipNextLeftButtonReleaseEvent + /** + * function SkipNextLeftButtonReleaseEvent * after calling this function, if the left mouse button * is down, the next left mouse button release event will be ignored. * It is is usefull for instance when closing a dialog on a mouse click, @@ -290,7 +291,7 @@ public: */ void SkipNextLeftButtonReleaseEvent(); - virtual void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, + virtual bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); /** @@ -433,7 +434,10 @@ public: * @param aPosition The current cursor position in logical (drawing) units. * @param aHotKey A key event used for application specific control if not zero. */ - virtual void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ) { } + virtual bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ) + { + return false; + } /** * Function OnSize diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index fbc4c73cfd..40d635cf1c 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -243,7 +243,7 @@ public: void Process_Config( wxCommandEvent& event ); void OnSelectTool( wxCommandEvent& aEvent ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); /** * Function GetProjectFileParametersList @@ -350,7 +350,7 @@ public: void ReCreateVToolbar(); void ReCreateOptToolbar(); void ReCreateMenuBar(); - void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); + bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); /** * Function OnModify diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index fbcd92aedd..ee97cfa83b 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -416,7 +416,7 @@ public: * @param aPosition The cursor position in logical (drawing) units. * @param aItem = NULL or pointer on a EDA_ITEM under the mouse cursor */ - void OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); + bool OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); /** * Function OnHotkeyDeleteItem @@ -582,7 +582,7 @@ public: */ void SwitchCanvas( wxCommandEvent& aEvent ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); /** * Function ShowDesignRulesEditor diff --git a/pagelayout_editor/controle.cpp b/pagelayout_editor/controle.cpp index 6d593faa16..e14c18df8a 100644 --- a/pagelayout_editor/controle.cpp +++ b/pagelayout_editor/controle.cpp @@ -32,14 +32,15 @@ #include -void PL_EDITOR_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, - int aHotKey ) +bool PL_EDITOR_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } wxPoint pos = aPosition; @@ -52,8 +53,10 @@ void PL_EDITOR_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, if( aHotKey ) { - OnHotKey( aDC, aHotKey, aPosition ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition ); } UpdateStatusBar(); + + return eventHandled; } diff --git a/pagelayout_editor/hotkeys.cpp b/pagelayout_editor/hotkeys.cpp index 74473599b0..5313763bb5 100644 --- a/pagelayout_editor/hotkeys.cpp +++ b/pagelayout_editor/hotkeys.cpp @@ -116,15 +116,7 @@ struct EDA_HOTKEY_CONFIG s_PlEditor_Hokeys_Descr[] = }; -/* OnHotKey. - * ** Commands are case insensitive ** - * Some commands are relative to the item under the mouse cursor - * aDC = current device context - * aHotkeyCode = hotkey code (ascii or wxWidget code for special keys) - * aPosition The cursor position in logical (drawing) units. - * aItem = NULL or pointer on a EDA_ITEM under the mouse cursor - */ -void PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, +bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem ) { bool busy = GetScreen()->GetCurItem() != NULL; @@ -142,14 +134,14 @@ void PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_Common_Hotkey_List ); if( HK_Descr == NULL ) - return; + return false; WORKSHEET_DATAITEM* item; switch( HK_Descr->m_Idcommand ) { case HK_NOT_FOUND: - return; + return false; case HK_LEFT_CLICK: OnLeftClick( aDC, aPosition ); @@ -235,7 +227,9 @@ void PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, break; default: - wxMessageBox( wxT("Unknown hotkey") ); - return; + wxMessageBox( wxT( "Unknown hotkey" ) ); + return false; } + + return true; } diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index e7a0f76181..b35e37ea7b 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -235,7 +235,7 @@ public: * @param aPosition The cursor position in logical (drawing) units. * @param aItem = NULL or pointer on a EDA_ITEM under the mouse cursor */ - void OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); + bool OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); void Process_Settings( wxCommandEvent& event ); void Process_Config( wxCommandEvent& event ); @@ -254,7 +254,7 @@ public: void ToPrinter( wxCommandEvent& event ); void Files_io( wxCommandEvent& event ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); /** Virtual function PrintPage * used to print a page diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index d84b7c05ad..d9200c84b9 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -281,19 +281,22 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode ) } -void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position // ( shift or ctrl key down are PAN command with mouse wheel) bool snapToGrid = true; + if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) snapToGrid = false; @@ -342,8 +345,10 @@ void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( aHotKey ) { - OnHotKey( aDC, aHotKey, aPosition ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition ); } UpdateStatusBar(); // Display new cursor coordinates + + return eventHandled; } diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 82ca685bca..1ae891a257 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -53,43 +53,43 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME ) -// Window events -EVT_CLOSE( FOOTPRINT_WIZARD_FRAME::OnCloseWindow ) -EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize ) -EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate ) + // Window events + EVT_CLOSE( FOOTPRINT_WIZARD_FRAME::OnCloseWindow ) + EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize ) + EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate ) -// Toolbar events -EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, - FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard ) + // Toolbar events + EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, + FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard ) -EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, - FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) + EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, + FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) -EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS, - FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) + EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS, + FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) -EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE, - FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint ) + EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE, + FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint ) -EVT_TOOL( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW, - FOOTPRINT_WIZARD_FRAME::Show3D_Frame ) + EVT_TOOL( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW, + FOOTPRINT_WIZARD_FRAME::Show3D_Frame ) -// listbox events -EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList ) + // listbox events + EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList ) #if wxCHECK_VERSION( 3, 0, 0 ) -EVT_GRID_CMD_CELL_CHANGED( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, - FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) + EVT_GRID_CMD_CELL_CHANGED( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, + FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) #else -EVT_GRID_CMD_CELL_CHANGE( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, - FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) + EVT_GRID_CMD_CELL_CHANGE( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, + FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) #endif -EVT_GRID_CMD_EDITOR_HIDDEN( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, - FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) + EVT_GRID_CMD_EDITOR_HIDDEN( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, + FOOTPRINT_WIZARD_FRAME::ParametersUpdated ) -EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset ) + EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset ) END_EVENT_TABLE() @@ -454,13 +454,15 @@ void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event ) } -void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); @@ -500,12 +502,17 @@ void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition case ' ': GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; + + default: + eventHandled = false; } SetCrossHairPosition( pos ); RefreshCrossHair( oldpos, aPosition, aDC ); UpdateStatusBar(); // Display new cursor coordinates + + return eventHandled; } diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index d65c309f34..e90cd00266 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -134,7 +134,7 @@ private: void ClickOnPageList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void LoadSettings( wxConfigBase* aCfg ); // override virtual void SaveSettings( wxConfigBase* aCfg ); // override virtual diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index fbf138753f..9b74f6a531 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -104,11 +104,11 @@ void PCB_EDIT_FRAME::CallMacros( wxDC* aDC, const wxPoint& aPosition, int aNumbe } -void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, +bool PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem ) { if( aHotkeyCode == 0 ) - return; + return false; bool itemCurrentlyEdited = GetCurItem() && GetCurItem()->GetFlags(); MODULE* module = NULL; @@ -128,7 +128,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit if( HK_Descr == NULL ) - return; + return false; int hk_id = HK_Descr->m_Idcommand; @@ -156,8 +156,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit { default: case HK_NOT_FOUND: - return; - break; + return false; case HK_LEFT_CLICK: OnLeftClick( aDC, aPosition ); @@ -349,7 +348,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_RESET_GRID_ORIGIN: - SetGridOrigin( wxPoint(0,0) ); + SetGridOrigin( wxPoint( 0,0 ) ); OnModify(); // because grid origin is saved in board, show as modified m_canvas->Refresh(); break; @@ -427,16 +426,16 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit case HK_ADD_MICROVIA: // Place a micro via if a track is in progress if( GetToolId() != ID_TRACK_BUTT ) - return; + return true; if( !itemCurrentlyEdited ) // no track in progress: nothing to do break; if( GetCurItem()->Type() != PCB_TRACE_T ) // Should not occur - return; + return true; if( !GetCurItem()->IsNew() ) - return; + return true; // place micro via and switch layer if( IsMicroViaAcceptable() ) @@ -461,13 +460,13 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit } if( GetToolId() != ID_TRACK_BUTT ) - return; + return true; if( GetCurItem()->Type() != PCB_TRACE_T ) - return; + return true; if( !GetCurItem()->IsNew() ) - return; + return true; evt_type = hk_id == HK_ADD_BLIND_BURIED_VIA ? ID_POPUP_PCB_PLACE_BLIND_BURIED_VIA : ID_POPUP_PCB_PLACE_THROUGH_VIA; @@ -574,6 +573,8 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit evt.SetId( evt_type ); GetEventHandler()->ProcessEvent( evt ); } + + return true; } diff --git a/pcbnew/hotkeys_module_editor.cpp b/pcbnew/hotkeys_module_editor.cpp index dcaed9df75..54786e79f6 100644 --- a/pcbnew/hotkeys_module_editor.cpp +++ b/pcbnew/hotkeys_module_editor.cpp @@ -18,11 +18,11 @@ */ -void FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, +bool FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) { if( aHotKey == 0 ) - return; + return false; bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE; BOARD_ITEM* item = GetCurItem(); @@ -41,14 +41,13 @@ void FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPos HK_Descr = GetDescriptorFromHotkey( aHotKey, module_edit_Hotkey_List ); if( HK_Descr == NULL ) - return; + return false; switch( HK_Descr->m_Idcommand ) { default: case HK_NOT_FOUND: - return; - break; + return false; case HK_HELP: // Display Current hotkey list DisplayHotkeyList( this, g_Module_Editor_Hokeys_Descr ); @@ -133,6 +132,8 @@ void FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPos OnHotkeyRotateItem( HK_ROTATE_ITEM ); break; } + + return true; } diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 9a3f0379a2..caf9518168 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -124,7 +124,7 @@ public: * case insensitive *

*/ - void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); + bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); bool OnHotkeyEditItem( int aIdCommand ); bool OnHotkeyDeleteItem( int aIdCommand ); @@ -137,7 +137,7 @@ public: */ void Show3D_Frame( wxCommandEvent& event ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void OnVerticalToolbar( wxCommandEvent& aEvent ); void OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ); diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 111b79bc76..2b893254b1 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -616,13 +616,15 @@ void FOOTPRINT_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event ) } -void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed @@ -642,10 +644,12 @@ void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, if( aHotKey ) { - OnHotKey( aDC, aHotKey, aPosition ); + eventHandled = OnHotKey( aDC, aHotKey, aPosition ); } UpdateStatusBar(); + + return eventHandled; } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 94d4eea73f..2651ee6117 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -591,13 +591,15 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) } -void FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { + bool eventHandled = true; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { m_movingCursorWithKeyboard = false; - return; + return false; } wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); @@ -637,12 +639,17 @@ void FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition case ' ': GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; + + default: + eventHandled = false; } SetCrossHairPosition( pos ); RefreshCrossHair( oldpos, aPosition, aDC ); UpdateStatusBar(); // Display new cursor coordinates + + return eventHandled; } diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index 311f150ed8..e8892ed3f1 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -112,7 +112,7 @@ private: void DClickOnFootprintList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); - void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void LoadSettings( wxConfigBase* aCfg ); // override virtual void SaveSettings( wxConfigBase* aCfg ); // override virtual