From 6d4dd3e17a139c7baaab81135a5e0bb1b165fbbd Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 6 Sep 2019 14:57:04 -0400 Subject: [PATCH] Pcbnew: fix size of graphics import warning dialog. Use the HTML_MESSAGE_BOX window to present the warning messages rather than wxMessageBox which would overflow the display when there were a lot of graphic items that could not be parsed. Fixes lp:1839565 https://bugs.launchpad.net/kicad/+bug/1839565 (cherry picked from commit 24454f510504668a24d1901217d38140f0eddadf) --- .../dialogs/dialog_display_info_HTML_base.cpp | 31 ++-- .../dialogs/dialog_display_info_HTML_base.fbp | 163 ++---------------- .../dialogs/dialog_display_info_HTML_base.h | 27 ++- common/html_messagebox.cpp | 20 ++- include/html_messagebox.h | 27 +-- pcbnew/import_gfx/dialog_import_gfx.cpp | 15 +- 6 files changed, 88 insertions(+), 195 deletions(-) diff --git a/common/dialogs/dialog_display_info_HTML_base.cpp b/common/dialogs/dialog_display_info_HTML_base.cpp index b118ace166..50aee03087 100644 --- a/common/dialogs/dialog_display_info_HTML_base.cpp +++ b/common/dialogs/dialog_display_info_HTML_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Aug 15 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,33 +12,36 @@ DIALOG_DISPLAY_HTML_TEXT_BASE::DIALOG_DISPLAY_HTML_TEXT_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( wxSize( -1,-1 ), wxDefaultSize ); - + wxBoxSizer* bMainSizer; bMainSizer = new wxBoxSizer( wxVERTICAL ); - + m_htmlWindow = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); m_htmlWindow->SetMinSize( wxSize( 400,250 ) ); - + bMainSizer->Add( m_htmlWindow, 1, wxALL|wxEXPAND, 5 ); - - m_buttonClose = new wxButton( this, wxID_CANCEL, _("OK"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonClose->SetDefault(); - bMainSizer->Add( m_buttonClose, 0, wxALIGN_RIGHT|wxALL, 5 ); - - + + m_sdbSizer1 = new wxStdDialogButtonSizer(); + m_sdbSizer1OK = new wxButton( this, wxID_OK ); + m_sdbSizer1->AddButton( m_sdbSizer1OK ); + m_sdbSizer1->Realize(); + + bMainSizer->Add( m_sdbSizer1, 0, wxBOTTOM|wxEXPAND, 5 ); + + this->SetSizer( bMainSizer ); this->Layout(); bMainSizer->Fit( this ); - + // Connect Events m_htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_DISPLAY_HTML_TEXT_BASE::OnHTMLLinkClicked ), NULL, this ); - m_buttonClose->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DISPLAY_HTML_TEXT_BASE::OnCloseButtonClick ), NULL, this ); + m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DISPLAY_HTML_TEXT_BASE::OnOKButtonClick ), NULL, this ); } DIALOG_DISPLAY_HTML_TEXT_BASE::~DIALOG_DISPLAY_HTML_TEXT_BASE() { // Disconnect Events m_htmlWindow->Disconnect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_DISPLAY_HTML_TEXT_BASE::OnHTMLLinkClicked ), NULL, this ); - m_buttonClose->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DISPLAY_HTML_TEXT_BASE::OnCloseButtonClick ), NULL, this ); - + m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DISPLAY_HTML_TEXT_BASE::OnOKButtonClick ), NULL, this ); + } diff --git a/common/dialogs/dialog_display_info_HTML_base.fbp b/common/dialogs/dialog_display_info_HTML_base.fbp index 12b56f9376..703e53bc0e 100644 --- a/common/dialogs/dialog_display_info_HTML_base.fbp +++ b/common/dialogs/dialog_display_info_HTML_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,8 @@ dialog_display_info_HTML_base 1000 none + + 1 dialog_display_info_HTML @@ -24,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -52,52 +55,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1,-1 bMainSizer wxVERTICAL none - + 5 wxALL|wxEXPAND 1 - + 1 1 1 @@ -149,120 +116,26 @@ - - - - - OnHTMLLinkClicked - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_RIGHT|wxALL + wxBOTTOM|wxEXPAND 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_CANCEL - OK - - 0 - - - 0 + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 - 1 - m_buttonClose - 1 - - + m_sdbSizer1 protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnCloseButtonClick - - - - - - - - - - - - - - - - - - - - - - - + OnOKButtonClick diff --git a/common/dialogs/dialog_display_info_HTML_base.h b/common/dialogs/dialog_display_info_HTML_base.h index da3890cdf6..c9468570df 100644 --- a/common/dialogs/dialog_display_info_HTML_base.h +++ b/common/dialogs/dialog_display_info_HTML_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Aug 15 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_DISPLAY_INFO_HTML_BASE_H__ -#define __DIALOG_DISPLAY_INFO_HTML_BASE_H__ +#pragma once #include #include @@ -18,8 +17,8 @@ #include #include #include -#include #include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -31,21 +30,21 @@ class DIALOG_DISPLAY_HTML_TEXT_BASE : public DIALOG_SHIM { private: - + protected: - wxButton* m_buttonClose; - + wxStdDialogButtonSizer* m_sdbSizer1; + wxButton* m_sdbSizer1OK; + // Virtual event handlers, overide them in your derived class virtual void OnHTMLLinkClicked( wxHtmlLinkEvent& event ) { event.Skip(); } - virtual void OnCloseButtonClick( wxCommandEvent& event ) { event.Skip(); } - - + virtual void OnOKButtonClick( wxCommandEvent& event ) { event.Skip(); } + + public: wxHtmlWindow* m_htmlWindow; - - DIALOG_DISPLAY_HTML_TEXT_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 ); + + DIALOG_DISPLAY_HTML_TEXT_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 ); ~DIALOG_DISPLAY_HTML_TEXT_BASE(); - + }; -#endif //__DIALOG_DISPLAY_INFO_HTML_BASE_H__ diff --git a/common/html_messagebox.cpp b/common/html_messagebox.cpp index d7cfdd17a6..8a74e6bd33 100644 --- a/common/html_messagebox.cpp +++ b/common/html_messagebox.cpp @@ -28,16 +28,20 @@ #include -HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* parent, const wxString& aTitle) : - DIALOG_DISPLAY_HTML_TEXT_BASE( parent, wxID_ANY, aTitle ) +HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle, + const wxPoint& aPosition, const wxSize& aSize ) : + DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize ) { m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight ); ListClear(); // Gives a default logical size (the actual size depends on the display definition) - SetSizeInDU( 320, 120 ); + if( aSize != wxDefaultSize ) + SetSizeInDU( aSize.x, aSize.y ); Center(); + + m_sdbSizer1OK->SetDefault(); } @@ -49,12 +53,14 @@ HTML_MESSAGE_BOX::~HTML_MESSAGE_BOX() } -void HTML_MESSAGE_BOX::OnCloseButtonClick( wxCommandEvent& event ) +void HTML_MESSAGE_BOX::OnOKButtonClick( wxCommandEvent& event ) { - // the dialog can be shown modal or not modal. + // the dialog can be shown quasi-model, modal, or not modeless. // therefore, use the right way to close it. - if( IsModal() ) - EndModal( 0 ); + if( IsQuasiModal() ) + EndQuasiModal( wxID_OK ); + else if( IsModal() ) + EndModal( wxID_OK ); else Destroy(); } diff --git a/include/html_messagebox.h b/include/html_messagebox.h index c1ea3c2199..f9a7d3c483 100644 --- a/include/html_messagebox.h +++ b/include/html_messagebox.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2011-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see CHANGELOG.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 @@ -27,9 +27,10 @@ /** -@file -Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder. -*/ + * @file include/html_messagebox.h + * + * Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder. + */ #include <../common/dialogs/dialog_display_info_HTML_base.h> @@ -41,10 +42,12 @@ class HTML_MESSAGE_BOX : public DIALOG_DISPLAY_HTML_TEXT_BASE { protected: // Handlers for HTML_MESSAGE_BOX_BASE events. - void OnCloseButtonClick( wxCommandEvent& event ) override; + void OnOKButtonClick( wxCommandEvent& event ) override; public: - HTML_MESSAGE_BOX( wxWindow* parent, const wxString& aTitle ); + HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle = wxEmptyString, + const wxPoint& aPosition = wxDefaultPosition, + const wxSize& aSize = wxDefaultSize ); ~HTML_MESSAGE_BOX() override; /** @@ -61,15 +64,15 @@ public: } /** - * Function ListSet * Add a list of items. + * * @param aList = a string containing items. Items are separated by '\n' */ void ListSet( const wxString& aList ); /** - * Function ListSet * Add a list of items. + * * @param aList = a wxArrayString containing items. */ void ListSet( const wxArrayString& aList ); @@ -77,15 +80,15 @@ public: void ListClear(); /** - * Function MessageSet - * adds a message (in bold) to message list. + * Add a message (in bold) to message list. + * * @param message = the message */ void MessageSet( const wxString& message ); /** - * Function AddHTML_Text - * adds html text (without any change) to message list. + * Add HTML text (without any change) to message list. + * * @param message = the text to add */ void AddHTML_Text( const wxString& message ); diff --git a/pcbnew/import_gfx/dialog_import_gfx.cpp b/pcbnew/import_gfx/dialog_import_gfx.cpp index 83171e343e..209ffb00ff 100644 --- a/pcbnew/import_gfx/dialog_import_gfx.cpp +++ b/pcbnew/import_gfx/dialog_import_gfx.cpp @@ -27,6 +27,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + #include "dialog_import_gfx.h" #include @@ -320,7 +322,8 @@ bool DIALOG_IMPORT_GFX::TransferDataFromWindow() m_importer->SetImportOffsetMM( m_origin ); m_scaleImport = DoubleValueFromString( UNSCALED_UNITS, m_textCtrlImportScale->GetValue() ); - // The line width is meant to be in pcbnew units, so we scale the import width before applying + // The line width is meant to be in pcbnew units, so we scale the import width before + // applying m_importer->SetLineWidthMM( m_lineWidth * m_scaleImport ); m_importer->SetPlugin( std::move( plugin ) ); @@ -330,11 +333,17 @@ bool DIALOG_IMPORT_GFX::TransferDataFromWindow() m_importer->Import( m_scaleImport ); // Get warning messages: - const std::string& warnings = m_importer->GetMessages(); + wxString warnings = m_importer->GetMessages(); // This isn't a fatal error so allow the dialog to close with wxID_OK. if( !warnings.empty() ) - wxMessageBox( warnings.c_str(), _( "Items Not Handled" ) ); + { + HTML_MESSAGE_BOX dlg( this, _( "Warning" ) ); + dlg.MessageSet( _( "Items in the imported file could not be handled properly." ) ); + warnings.Replace( "\n", "
" ); + dlg.AddHTML_Text( warnings ); + dlg.ShowModal(); + } } else {