From db178dcdafcb9dcd494ce5e4ef196e328f5f4397 Mon Sep 17 00:00:00 2001 From: Chris Pavlina Date: Fri, 15 Jan 2016 20:56:00 -0500 Subject: [PATCH] Eeschema options+hotkeys fixes Fix wxTreeListCtrl column sizing Minor: fix signed/unsigned comparison Remove unnecessary m_parent direct access --- common/dialogs/dialog_hotkeys_editor.cpp | 36 ++++++++++++++++---- eeschema/dialogs/dialog_eeschema_options.cpp | 16 ++++++--- eeschema/dialogs/dialog_eeschema_options.h | 5 ++- include/dialog_hotkeys_editor.h | 12 ++++++- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/common/dialogs/dialog_hotkeys_editor.cpp b/common/dialogs/dialog_hotkeys_editor.cpp index ee1551a9d2..ac50980d91 100644 --- a/common/dialogs/dialog_hotkeys_editor.cpp +++ b/common/dialogs/dialog_hotkeys_editor.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -52,9 +53,8 @@ HOTKEY_LIST_CTRL::HOTKEY_LIST_CTRL( wxWindow *aParent, const HOTKEYS_SECTIONS& a AppendColumn( _( "Command" ) ); AppendColumn( _( "Hotkey" ) ); - SetColumnWidth( 1, 100 ); - Bind( wxEVT_CHAR, &HOTKEY_LIST_CTRL::OnChar, this ); + Bind( wxEVT_SIZE, &HOTKEY_LIST_CTRL::OnSize, this ); } @@ -70,9 +70,34 @@ HOTKEYS_SECTIONS HOTKEY_LIST_CTRL::Sections( EDA_HOTKEY_CONFIG* aHotkeys ) } +void HOTKEY_LIST_CTRL::OnSize( wxSizeEvent& aEvent ) +{ + // Handle this manually - wxTreeListCtrl screws up the width of the first column + wxDataViewCtrl* view = GetDataView(); + + if( !view ) + return; + + const wxRect rect = GetClientRect(); + view->SetSize( rect ); + +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + { + wxWindow* const view = GetView(); + view->Refresh(); + view->Update(); + } +#endif + + SetColumnWidth( 1, 100 ); + SetColumnWidth( 0, rect.width - 120 ); +} + + void HOTKEY_LIST_CTRL::DeselectRow( int aRow ) { - wxASSERT( aRow >= 0 && aRow < (int)m_items.size() ); + wxASSERT( aRow >= 0 ); + wxASSERT( (size_t)( aRow ) < m_items.size() ); Unselect( m_items[aRow] ); } @@ -277,7 +302,7 @@ bool HOTKEY_LIST_CTRL::ResolveKeyConflicts( long aKey, const wxString& aSectionT KeyNameFromKeyCode( aKey ), GetChars( info ), *(conflictingSection->m_Title) ); - wxMessageDialog dlg( m_parent, msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT ); + wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT ); if( dlg.ShowModal() == wxID_YES ) { @@ -358,7 +383,6 @@ void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) : HOTKEYS_EDITOR_DIALOG_BASE( aParent ), - m_parent( aParent ), m_hotkeys( aHotkeys ) { m_hotkeyListCtrl = new HOTKEY_LIST_CTRL( this, HOTKEY_LIST_CTRL::Sections( aHotkeys ) ); @@ -391,7 +415,7 @@ bool HOTKEYS_EDITOR_DIALOG::TransferDataFromWindow() return false; // save the hotkeys - m_parent->WriteHotkeyConfig( m_hotkeys ); + GetParent()->WriteHotkeyConfig( m_hotkeys ); return true; } diff --git a/eeschema/dialogs/dialog_eeschema_options.cpp b/eeschema/dialogs/dialog_eeschema_options.cpp index 35c68c161a..28c715e36a 100644 --- a/eeschema/dialogs/dialog_eeschema_options.cpp +++ b/eeschema/dialogs/dialog_eeschema_options.cpp @@ -47,7 +47,7 @@ enum IMP_EXP_MENU_IDS ID_EXPORT_HOTKEYS }; -DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS( wxWindow* parent ) : +DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS( SCH_EDIT_FRAME* parent ) : DIALOG_EESCHEMA_OPTIONS_BASE( parent ) { m_choiceUnits->SetFocus(); @@ -80,6 +80,12 @@ DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS( wxWindow* parent ) : } +SCH_EDIT_FRAME* DIALOG_EESCHEMA_OPTIONS::GetParent() +{ + return static_cast( DIALOG_EESCHEMA_OPTIONS_BASE::GetParent() ); +} + + void DIALOG_EESCHEMA_OPTIONS::OnImpExpClick( wxCommandEvent& aEvent ) { wxMenu menu; @@ -103,19 +109,19 @@ void DIALOG_EESCHEMA_OPTIONS::OnMenu( wxCommandEvent& aEvent ) { case ID_IMPORT_PREFS: aEvent.SetId( ID_CONFIG_READ ); - static_cast( m_parent )->Process_Config( aEvent ); + GetParent()->Process_Config( aEvent ); break; case ID_EXPORT_PREFS: aEvent.SetId( ID_CONFIG_SAVE ); - static_cast( m_parent )->Process_Config( aEvent ); + GetParent()->Process_Config( aEvent ); break; case ID_IMPORT_HOTKEYS: aEvent.SetId( ID_PREFERENCES_HOTKEY_IMPORT_CONFIG ); - static_cast( m_parent )->Process_Config( aEvent ); + GetParent()->Process_Config( aEvent ); break; case ID_EXPORT_HOTKEYS: aEvent.SetId( ID_PREFERENCES_HOTKEY_EXPORT_CONFIG ); - static_cast( m_parent )->Process_Config( aEvent ); + GetParent()->Process_Config( aEvent ); break; default: wxFAIL_MSG("Unexpected menu ID"); diff --git a/eeschema/dialogs/dialog_eeschema_options.h b/eeschema/dialogs/dialog_eeschema_options.h index 2235b0e115..2afc07a198 100644 --- a/eeschema/dialogs/dialog_eeschema_options.h +++ b/eeschema/dialogs/dialog_eeschema_options.h @@ -35,6 +35,7 @@ #include class HOTKEY_LIST_CTRL; +class SCH_EDIT_FRAME; class DIALOG_EESCHEMA_OPTIONS : public DIALOG_EESCHEMA_OPTIONS_BASE { @@ -96,7 +97,9 @@ public: * * @param parent The dialog's parent */ - DIALOG_EESCHEMA_OPTIONS( wxWindow* parent ); + DIALOG_EESCHEMA_OPTIONS( SCH_EDIT_FRAME* parent ); + + virtual SCH_EDIT_FRAME* GetParent(); /** * Function GetUnitsSelection diff --git a/include/dialog_hotkeys_editor.h b/include/dialog_hotkeys_editor.h index 072a7478dd..ea7b3d3e02 100644 --- a/include/dialog_hotkeys_editor.h +++ b/include/dialog_hotkeys_editor.h @@ -173,6 +173,12 @@ protected: * @param aEvent is the key press event, the keycode is retrieved from it */ void OnChar( wxKeyEvent& aEvent ); + + /** + * Function OnSize + * Handle resizing of the control. Overrides the buggy wxTreeListCtrl::OnSize. + */ + void OnSize( wxSizeEvent& aEvent ); }; @@ -184,7 +190,6 @@ protected: class HOTKEYS_EDITOR_DIALOG : public HOTKEYS_EDITOR_DIALOG_BASE { protected: - EDA_BASE_FRAME* m_parent; struct EDA_HOTKEY_CONFIG* m_hotkeys; HOTKEY_LIST_CTRL* m_hotkeyListCtrl; @@ -192,6 +197,11 @@ protected: bool TransferDataToWindow(); bool TransferDataFromWindow(); + virtual EDA_BASE_FRAME* GetParent() + { + return static_cast( HOTKEYS_EDITOR_DIALOG_BASE::GetParent() ); + } + public: HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys );