diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 42936ef233..63c7974d4a 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -594,7 +594,7 @@ void EDA_DRAW_FRAME::SetPresetGrid( int aIndex ) } -int EDA_DRAW_FRAME::BlockCommand( int key ) +int EDA_DRAW_FRAME::BlockCommand( EDA_KEY key ) { return 0; } @@ -767,7 +767,7 @@ wxString EDA_DRAW_FRAME::LengthDoubleToString( double aValue, bool aConvertToMil } -bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosition ) +bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition ) { BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index dff95aee86..073844bac3 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -315,7 +315,8 @@ void DISPLAY_FOOTPRINTS_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) } -bool DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, + EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/cvpcb/class_DisplayFootprintsFrame.h b/cvpcb/class_DisplayFootprintsFrame.h index 6f4b0e9bb0..f4cbf7c0ee 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 ); - bool GeneralControl( wxDC* DC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* DC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); void InstallOptionsDisplay( wxCommandEvent& event ); MODULE* Get_Module( const wxString& CmpName ); diff --git a/eeschema/block.cpp b/eeschema/block.cpp index e4b38e9f91..9edd9d43fa 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -62,7 +62,7 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); -int SCH_EDIT_FRAME::BlockCommand( int key ) +int SCH_EDIT_FRAME::BlockCommand( EDA_KEY key ) { int cmd = BLOCK_IDLE; diff --git a/eeschema/block_libedit.cpp b/eeschema/block_libedit.cpp index 5dc235f746..865d4e6736 100644 --- a/eeschema/block_libedit.cpp +++ b/eeschema/block_libedit.cpp @@ -41,7 +41,7 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx bool aErase ); -int LIB_EDIT_FRAME::BlockCommand( int key ) +int LIB_EDIT_FRAME::BlockCommand( EDA_KEY key ) { int cmd = BLOCK_IDLE; @@ -51,11 +51,18 @@ int LIB_EDIT_FRAME::BlockCommand( int key ) cmd = key & 0xFF; break; - case -1: + case EDA_KEY_C( 0xffffffff ): // -1 + // Historically, -1 has been used as a key, which can cause bit flag + // clashes with unaware code. On debug builds, catch any old code that + // might still be doing this. TODO: remove if sure all this old code is gone. + wxFAIL_MSG( "negative EDA_KEY value should be converted to GR_KEY_INVALID" ); + // fall through on release builds + + case GR_KEY_INVALID: cmd = BLOCK_PRESELECT_MOVE; break; - case 0: + case GR_KEY_NONE: cmd = BLOCK_MOVE; break; diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index 9832de090e..362b1fc66a 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -202,7 +202,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aF } -bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; @@ -249,7 +249,7 @@ bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH } -bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; @@ -291,7 +291,7 @@ bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH } -bool LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 7b9cad055e..06c4169acd 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -332,7 +332,7 @@ public: bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); void LoadSettings( wxConfigBase* aCfg ); @@ -606,7 +606,7 @@ public: * returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to * the \a aKey (ALT, SHIFT ALT ..) */ - virtual int BlockCommand( int aKey ); + virtual int BlockCommand( EDA_KEY aKey ); /** * Function HandleBlockPlace diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 45b820f8d0..f057a4f649 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -269,7 +269,7 @@ public: void Process_Config( wxCommandEvent& event ); void OnSelectTool( wxCommandEvent& aEvent ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); /** * Function GetProjectFileParametersList @@ -1228,7 +1228,7 @@ public: * @param aKey = the key modifiers (Alt, Shift ...) * @return the block command id (BLOCK_MOVE, BLOCK_COPY...) */ - virtual int BlockCommand( int aKey ); + virtual int BlockCommand( EDA_KEY aKey ); /** * Function HandleBlockPlace diff --git a/eeschema/viewlib_frame.h b/eeschema/viewlib_frame.h index ab7ecb21cf..4aed86232b 100644 --- a/eeschema/viewlib_frame.h +++ b/eeschema/viewlib_frame.h @@ -87,7 +87,7 @@ public: void ClickOnCmpList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const; diff --git a/gerbview/block.cpp b/gerbview/block.cpp index 1218322b54..8494f75a1b 100644 --- a/gerbview/block.cpp +++ b/gerbview/block.cpp @@ -47,7 +47,7 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx bool erase ); -int GERBVIEW_FRAME::BlockCommand( int key ) +int GERBVIEW_FRAME::BlockCommand( EDA_KEY key ) { int cmd = 0; diff --git a/gerbview/controle.cpp b/gerbview/controle.cpp index ace281c534..fc98571378 100644 --- a/gerbview/controle.cpp +++ b/gerbview/controle.cpp @@ -33,7 +33,7 @@ #include -bool GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 383ab544fc..6bac9ff96e 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -546,7 +546,7 @@ public: * returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to * the \a aKey (ALT, SHIFT ALT ..) */ - virtual int BlockCommand( int key ); + virtual int BlockCommand( EDA_KEY key ); /** * Function HandleBlockPlace @@ -631,7 +631,7 @@ public: bool LoadExcellonFiles( const wxString& aFileName ); bool Read_EXCELLON_File( const wxString& aFullFileName ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); /** * Set Size Items (Lines, Flashes) from DCodes List diff --git a/include/common.h b/include/common.h index b881444a01..4ddd157be5 100644 --- a/include/common.h +++ b/include/common.h @@ -4,7 +4,7 @@ * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2008-2015 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.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 @@ -33,6 +33,7 @@ #define INCLUDE__COMMON_H_ #include +#include #include #include @@ -49,17 +50,21 @@ class REPORTER; // Flag for special keys -#define GR_KB_RIGHTSHIFT 0x10000000 /* Keybd states: right - * shift key depressed */ -#define GR_KB_LEFTSHIFT 0x20000000 /* left shift key depressed - */ -#define GR_KB_CTRL 0x40000000 // CTRL depressed -#define GR_KB_ALT 0x80000000 // ALT depressed -#define GR_KB_SHIFT (GR_KB_LEFTSHIFT | GR_KB_RIGHTSHIFT) -#define GR_KB_SHIFTCTRL (GR_KB_SHIFT | GR_KB_CTRL) -#define MOUSE_MIDDLE 0x08000000 /* Middle button mouse - * flag for block commands - */ +// This type could be extended to 64 bits to add room for more flags. +// For compatibility with old code, keep flag bits out of the least +// significant nibble (0xF). +typedef uint32_t EDA_KEY; +#define EDA_KEY_C UINT32_C + +static const EDA_KEY GR_KB_RIGHTSHIFT = EDA_KEY_C( 0x01000000 ); +static const EDA_KEY GR_KB_LEFTSHIFT = EDA_KEY_C( 0x02000000 ); +static const EDA_KEY GR_KB_CTRL = EDA_KEY_C( 0x04000000 ); +static const EDA_KEY GR_KB_ALT = EDA_KEY_C( 0x08000000 ); +static const EDA_KEY GR_KB_SHIFT = GR_KB_LEFTSHIFT | GR_KB_RIGHTSHIFT; +static const EDA_KEY GR_KB_SHIFTCTRL = GR_KB_SHIFT | GR_KB_CTRL; +static const EDA_KEY MOUSE_MIDDLE = EDA_KEY_C( 0x10000000 ); +static const EDA_KEY GR_KEY_INVALID = EDA_KEY_C( 0x80000000 ); +static const EDA_KEY GR_KEY_NONE = EDA_KEY_C( 0 ); /// default name for nameless projects #define NAMELESS_PROJECT wxT( "noname" ) diff --git a/include/draw_frame.h b/include/draw_frame.h index 791a3ff17b..7765e975c4 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -516,7 +516,7 @@ 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 bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ) + virtual bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) { return false; } @@ -642,7 +642,7 @@ public: * initializes the block command including the command type, initial position, * and other variables. */ - virtual bool HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosition ); + virtual bool HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition ); /** * Function BlockCommand @@ -653,7 +653,7 @@ public: * @param aKey = the key modifiers (Alt, Shift ...) * @return the block command id (BLOCK_MOVE, BLOCK_COPY...) */ - virtual int BlockCommand( int aKey ); + virtual int BlockCommand( EDA_KEY aKey ); /** * Function HandleBlockPlace( ) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 68f304bc48..103172c2fa 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -620,7 +620,7 @@ public: ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas() void UseGalCanvas( bool aEnable ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); /** * Function ShowDesignRulesEditor @@ -716,7 +716,7 @@ public: * @param aKey = the key modifiers (Alt, Shift ...) * @return the block command id (BLOCK_MOVE, BLOCK_COPY...) */ - virtual int BlockCommand( int aKey ); + virtual int BlockCommand( EDA_KEY aKey ); /** * Function HandleBlockPlace() diff --git a/pagelayout_editor/controle.cpp b/pagelayout_editor/controle.cpp index e14c18df8a..8405efce5f 100644 --- a/pagelayout_editor/controle.cpp +++ b/pagelayout_editor/controle.cpp @@ -32,7 +32,7 @@ #include -bool PL_EDITOR_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool PL_EDITOR_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index ba3b7aebe1..67a5a29fd4 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -267,7 +267,7 @@ public: void ToPrinter( wxCommandEvent& event ); void Files_io( wxCommandEvent& event ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); /** Virtual function PrintPage * used to print a page diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index ae09495a12..fdbf2d874b 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -178,7 +178,7 @@ void DIALOG_BLOCK_OPTIONS::ExecuteCommand( wxCommandEvent& event ) } -int PCB_EDIT_FRAME::BlockCommand( int aKey ) +int PCB_EDIT_FRAME::BlockCommand( EDA_KEY aKey ) { int cmd = 0; diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index 47a5dc54be..c156cc7119 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -78,7 +78,7 @@ static void MoveMarkedItems( MODULE* module, wxPoint offset ); static void DeleteMarkedItems( MODULE* module ); -int FOOTPRINT_EDIT_FRAME::BlockCommand( int key ) +int FOOTPRINT_EDIT_FRAME::BlockCommand( EDA_KEY key ) { int cmd; @@ -88,7 +88,14 @@ int FOOTPRINT_EDIT_FRAME::BlockCommand( int key ) cmd = key & 0xFF; break; - case - 1: + case EDA_KEY_C( 0xffffffff ): // -1 + // Historically, -1 has been used as a key, which can cause bit flag + // clashes with unaware code. On debug builds, catch any old code that + // might still be doing this. TODO: remove if sure all this old code is gone. + wxFAIL_MSG( "negative EDA_KEY value should be converted to GR_KEY_INVALID" ); + // fall through on release builds + + case GR_KEY_INVALID: cmd = BLOCK_PRESELECT_MOVE; break; diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index d9475f2179..c7b231b9fa 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -282,7 +282,7 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode ) } -bool PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 11b43972e3..47bb737535 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -452,7 +452,7 @@ void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event ) } -bool FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index a8ca4cb1d4..65e6d0d78d 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -151,7 +151,7 @@ private: void ClickOnPageList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); void LoadSettings( wxConfigBase* aCfg ); // override virtual void SaveSettings( wxConfigBase* aCfg ); // override virtual diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index ce32a2ef18..9d81f4876c 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -167,7 +167,7 @@ public: */ void Show3D_Frame( wxCommandEvent& event ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); void OnVerticalToolbar( wxCommandEvent& aEvent ); void OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ); @@ -242,7 +242,7 @@ public: bool Clear_Pcb( bool aQuery ); /* handlers for block commands */ - virtual int BlockCommand( int key ); + virtual int BlockCommand( EDA_KEY key ); /** * Function HandleBlockPlace diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 5eb232c387..4e3f822199 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -696,7 +696,7 @@ void FOOTPRINT_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event ) } -bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 6a39ae98fe..ef2a97e9dc 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -591,7 +591,7 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) } -bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) +bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { bool eventHandled = true; diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index f0cf28d551..2e1909b6d3 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -104,7 +104,7 @@ private: void DClickOnFootprintList( wxCommandEvent& event ); void OnSetRelativeOffset( wxCommandEvent& event ); - bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); + bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ); ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const;