From f32f14dc8ff72fc2d84885f732e19857175ac67b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 12 Mar 2018 22:45:17 +0000 Subject: [PATCH] Add WX_TEXT_ENTRY_DIALOG which inherits from DIALOG_SHIM. Fixes: lp:1754977 * https://bugs.launchpad.net/kicad/+bug/1754977 --- common/CMakeLists.txt | 2 + common/dialogs/dialog_text_entry.cpp | 57 ++++ common/dialogs/dialog_text_entry.h | 52 +++ common/dialogs/dialog_text_entry_base.cpp | 53 +++ common/dialogs/dialog_text_entry_base.fbp | 310 ++++++++++++++++++ common/dialogs/dialog_text_entry_base.h | 50 +++ .../dialogs/dialog_edit_component_in_lib.cpp | 9 +- pcbnew/dialogs/dialog_design_rules.cpp | 3 +- .../dialog_edit_footprint_for_BoardEditor.cpp | 3 +- .../dialog_edit_footprint_for_fp_editor.cpp | 3 +- pcbnew/edgemod.cpp | 3 +- pcbnew/footprint_libraries_utils.cpp | 3 +- pcbnew/microwave.cpp | 13 +- pcbnew/microwave/microwave_inductor.cpp | 5 +- 14 files changed, 549 insertions(+), 17 deletions(-) create mode 100644 common/dialogs/dialog_text_entry.cpp create mode 100644 common/dialogs/dialog_text_entry.h create mode 100644 common/dialogs/dialog_text_entry_base.cpp create mode 100644 common/dialogs/dialog_text_entry_base.fbp create mode 100644 common/dialogs/dialog_text_entry_base.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a061a8c534..b2f116ede5 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -163,6 +163,8 @@ set( COMMON_DLG_SRCS dialogs/dialog_image_editor_base.cpp dialogs/dialog_list_selector_base.cpp dialogs/dialog_page_settings_base.cpp + dialogs/dialog_text_entry_base.cpp + dialogs/dialog_text_entry.cpp dialogs/wx_html_report_panel.cpp dialogs/wx_html_report_panel_base.cpp ) diff --git a/common/dialogs/dialog_text_entry.cpp b/common/dialogs/dialog_text_entry.cpp new file mode 100644 index 0000000000..f6ef296b6b --- /dev/null +++ b/common/dialogs/dialog_text_entry.cpp @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 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 + * 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 + */ + +#include +#include + +#include + + +WX_TEXT_ENTRY_DIALOG::WX_TEXT_ENTRY_DIALOG( wxWindow* aParent, + const wxString& aFieldLabel, + const wxString& aCaption, + const wxString& aDefaultValue ) : + WX_TEXT_ENTRY_DIALOG_BASE( aParent, wxID_ANY, aCaption, wxDefaultPosition, wxDefaultSize ) +{ + m_label->SetLabel( aFieldLabel ); + m_textCtrl->SetValue( aDefaultValue ); +} + + +void WX_TEXT_ENTRY_DIALOG::SetTextValidator( wxTextValidatorStyle style ) +{ + SetTextValidator( wxTextValidator(style) ); +} + + +void WX_TEXT_ENTRY_DIALOG::SetTextValidator( const wxTextValidator& validator ) +{ + m_textCtrl->SetValidator( validator ); +} + + +wxString WX_TEXT_ENTRY_DIALOG::GetValue() +{ + return m_textCtrl->GetValue(); +} + diff --git a/common/dialogs/dialog_text_entry.h b/common/dialogs/dialog_text_entry.h new file mode 100644 index 0000000000..9ae0cdcb3e --- /dev/null +++ b/common/dialogs/dialog_text_entry.h @@ -0,0 +1,52 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 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 + * 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 + */ + + +/** + * A KICAD version of wxTextEntryDialog which supports the various improvments/work-arounds + * from DIALOG_SHIM. + */ + + +#ifndef _DIALOG_TEXT_ENTRY_H_ +#define _DIALOG_TEXT_ENTRY_H_ + +#include + + +class wxTextValidator; + + +class WX_TEXT_ENTRY_DIALOG : public WX_TEXT_ENTRY_DIALOG_BASE +{ +public: + WX_TEXT_ENTRY_DIALOG( wxWindow* aParent, const wxString& aLabel, const wxString& aCaption, + const wxString& aDefaultValue = wxEmptyString ); + + void SetTextValidator( wxTextValidatorStyle style ); + void SetTextValidator( const wxTextValidator& validator ); + + wxString GetValue(); +}; + +#endif // _DIALOG_TEXT_ENTRY_H_ diff --git a/common/dialogs/dialog_text_entry_base.cpp b/common/dialogs/dialog_text_entry_base.cpp new file mode 100644 index 0000000000..16e0c02f81 --- /dev/null +++ b/common/dialogs/dialog_text_entry_base.cpp @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Dec 30 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_text_entry_base.h" + +/////////////////////////////////////////////////////////////////////////// + +WX_TEXT_ENTRY_DIALOG_BASE::WX_TEXT_ENTRY_DIALOG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizerContent; + bSizerContent = new wxBoxSizer( wxVERTICAL ); + + m_label = new wxStaticText( this, wxID_ANY, _("MyLabel"), wxDefaultPosition, wxDefaultSize, 0 ); + m_label->Wrap( -1 ); + bSizerContent->Add( m_label, 0, wxALL|wxEXPAND, 5 ); + + m_textCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_textCtrl->SetMinSize( wxSize( 300,-1 ) ); + + bSizerContent->Add( m_textCtrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + + + bSizerMain->Add( bSizerContent, 1, wxALL|wxEXPAND, 5 ); + + m_sdbSizer1 = new wxStdDialogButtonSizer(); + m_sdbSizer1OK = new wxButton( this, wxID_OK ); + m_sdbSizer1->AddButton( m_sdbSizer1OK ); + m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); + m_sdbSizer1->Realize(); + + bSizerMain->Add( m_sdbSizer1, 0, wxEXPAND, 5 ); + + + this->SetSizer( bSizerMain ); + this->Layout(); + bSizerMain->Fit( this ); + + this->Centre( wxBOTH ); +} + +WX_TEXT_ENTRY_DIALOG_BASE::~WX_TEXT_ENTRY_DIALOG_BASE() +{ +} diff --git a/common/dialogs/dialog_text_entry_base.fbp b/common/dialogs/dialog_text_entry_base.fbp new file mode 100644 index 0000000000..97db3bc0bd --- /dev/null +++ b/common/dialogs/dialog_text_entry_base.fbp @@ -0,0 +1,310 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_text_entry_base + 1000 + none + 1 + dialog_text_entry_base + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + WX_TEXT_ENTRY_DIALOG_BASE + + -1,-1 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizerMain + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 1 + + + bSizerContent + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + MyLabel + + 0 + + + 0 + + 1 + m_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + 300,-1 + 1 + m_textCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer1 + protected + + + + + + + + + + + + + + diff --git a/common/dialogs/dialog_text_entry_base.h b/common/dialogs/dialog_text_entry_base.h new file mode 100644 index 0000000000..6c25971469 --- /dev/null +++ b/common/dialogs/dialog_text_entry_base.h @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Dec 30 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_TEXT_ENTRY_BASE_H__ +#define __DIALOG_TEXT_ENTRY_BASE_H__ + +#include +#include +#include +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class WX_TEXT_ENTRY_DIALOG_BASE +/////////////////////////////////////////////////////////////////////////////// +class WX_TEXT_ENTRY_DIALOG_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticText* m_label; + wxTextCtrl* m_textCtrl; + wxStdDialogButtonSizer* m_sdbSizer1; + wxButton* m_sdbSizer1OK; + wxButton* m_sdbSizer1Cancel; + + public: + + WX_TEXT_ENTRY_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~WX_TEXT_ENTRY_DIALOG_BASE(); + +}; + +#endif //__DIALOG_TEXT_ENTRY_BASE_H__ diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index eb375964fd..549b6bbade 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -326,7 +327,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::EditAliasOfPart( wxCommandEvent& aEvent ) return; } - wxTextEntryDialog dlg( this, _( "New Alias:" ), _( "Symbol alias:" ), aliasname ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "New Alias:" ), _( "Symbol alias:" ), aliasname ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user @@ -343,7 +344,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& event ) { wxString aliasname; - wxTextEntryDialog dlg( this, _( "New Alias:" ), _( "Symbol alias:" ), aliasname ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "New Alias:" ), _( "Symbol alias:" ), aliasname ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user @@ -522,7 +523,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& event if( component == NULL ) return; - wxTextEntryDialog dlg( this, _( "Add Footprint Filter" ), _( "Footprint Filter" ), Line ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "Add Footprint Filter" ), _( "Footprint Filter" ), Line ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user @@ -575,7 +576,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::EditOneFootprintFilter( wxCommandEvent& e wxString filter = m_FootprintFilterListBox->GetStringSelection(); - wxTextEntryDialog dlg( this, wxEmptyString, _( "Edit footprint filter" ), filter ); + WX_TEXT_ENTRY_DIALOG dlg( this, wxEmptyString, _( "Edit footprint filter" ), filter ); if( dlg.ShowModal() != wxID_OK ) return; // Aborted by user diff --git a/pcbnew/dialogs/dialog_design_rules.cpp b/pcbnew/dialogs/dialog_design_rules.cpp index 2a55429e50..a858687ba3 100644 --- a/pcbnew/dialogs/dialog_design_rules.cpp +++ b/pcbnew/dialogs/dialog_design_rules.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -731,7 +732,7 @@ void DIALOG_DESIGN_RULES::OnAddNetclassClick( wxCommandEvent& event ) // @todo set validator to ensure net class name is valid rather than all of the checks // after the OK button has been selected. - wxTextEntryDialog dlg( this, _( "New Net Class Name:" ), wxEmptyString, class_name ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "New Net Class Name:" ), wxEmptyString, class_name ); if( dlg.ShowModal() != wxID_OK ) return; // canceled by user diff --git a/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp index a7ad2bb8cc..c689e98fb5 100644 --- a/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -488,7 +489,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::Edit3DShapeFileName() // Edit filename wxString filename = m_3D_ShapeNameListBox->GetStringSelection(); - wxTextEntryDialog dlg( this, wxEmptyString, wxEmptyString, filename ); + WX_TEXT_ENTRY_DIALOG dlg( this, wxEmptyString, wxEmptyString, filename ); bool hasAlias; S3D_FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver(); diff --git a/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp b/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp index 28da4363b8..dbdc7991ff 100644 --- a/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -341,7 +342,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::Edit3DShapeFileName() // Edit filename wxString filename = m_3D_ShapeNameListBox->GetStringSelection(); - wxTextEntryDialog dlg( this, wxEmptyString, wxEmptyString, filename ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filepath:" ), _( "Edit 3D Shape Name" ), filename ); bool hasAlias; S3D_FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver(); diff --git a/pcbnew/edgemod.cpp b/pcbnew/edgemod.cpp index e105370f75..54f99ed7b9 100644 --- a/pcbnew/edgemod.cpp +++ b/pcbnew/edgemod.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -251,7 +252,7 @@ void FOOTPRINT_EDIT_FRAME::Enter_Edge_Width( EDGE_MODULE* aEdge ) wxString buffer; buffer = StringFromValue( g_UserUnit, GetDesignSettings().m_ModuleSegmentWidth ); - wxTextEntryDialog dlg( this, _( "New Width:" ), _( "Edge Width" ), buffer ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "New Width:" ), _( "Edge Width" ), buffer ); if( dlg.ShowModal() != wxID_OK ) return; // canceled by user diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 7a1e12f4b8..f1b4d2903d 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -810,7 +811,7 @@ MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName ) // Ask for the new module name if( moduleName.IsEmpty() ) { - wxTextEntryDialog dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName ); + WX_TEXT_ENTRY_DIALOG dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName ); dlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &moduleName ) ); if( dlg.ShowModal() != wxID_OK ) diff --git a/pcbnew/microwave.cpp b/pcbnew/microwave.cpp index 7c16d2db98..5ad0ced945 100644 --- a/pcbnew/microwave.cpp +++ b/pcbnew/microwave.cpp @@ -42,7 +42,8 @@ #include #include #include -#include // +#include +#include #include #include @@ -264,8 +265,8 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) break; } - wxString value = StringFromValue( g_UserUnit, gap_size ); - wxTextEntryDialog dlg( this, msg, _( "Create microwave module" ), value ); + wxString value = StringFromValue( g_UserUnit, gap_size ); + WX_TEXT_ENTRY_DIALOG dlg( this, msg, _( "Create microwave module" ), value ); if( dlg.ShowModal() != wxID_OK ) { @@ -282,8 +283,8 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) { double fcoeff = 10.0, fval; msg.Printf( wxT( "%3.1f" ), angle / fcoeff ); - wxTextEntryDialog angledlg( this, _( "Angle in degrees:" ), - _( "Create microwave module" ), msg ); + WX_TEXT_ENTRY_DIALOG angledlg( this, _( "Angle in degrees:" ), + _( "Create microwave module" ), msg ); if( angledlg.ShowModal() != wxID_OK ) { @@ -720,7 +721,7 @@ void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* aModule ) // Entrer the desired length of the gap. msg = StringFromValue( g_UserUnit, gap_size ); - wxTextEntryDialog dlg( this, _( "Gap:" ), _( "Create Microwave Gap" ), msg ); + WX_TEXT_ENTRY_DIALOG dlg( this, _( "Gap:" ), _( "Create Microwave Gap" ), msg ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user diff --git a/pcbnew/microwave/microwave_inductor.cpp b/pcbnew/microwave/microwave_inductor.cpp index 7239ca8886..9e0e1edac2 100644 --- a/pcbnew/microwave/microwave_inductor.cpp +++ b/pcbnew/microwave/microwave_inductor.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -306,7 +307,7 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern, // Enter the desired length. msg = StringFromValue( g_UserUnit, inductorPattern.m_length ); - wxTextEntryDialog dlg( nullptr, wxEmptyString, _( "Length of Trace:" ), msg ); + WX_TEXT_ENTRY_DIALOG dlg( nullptr, _( "Length of Trace:" ), wxEmptyString, msg ); if( dlg.ShowModal() != wxID_OK ) return nullptr; // canceled by user @@ -335,7 +336,7 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern, // Generate footprint. the value is also used as footprint name. msg = "L"; - wxTextEntryDialog cmpdlg( nullptr, wxEmptyString, _( "Component Value:" ), msg ); + WX_TEXT_ENTRY_DIALOG cmpdlg( nullptr, _( "Component Value:" ), wxEmptyString, msg ); cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) ); if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() )