You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <dialogs/dialog_book_reporter.h>
  24. #include <widgets/wx_html_report_box.h>
  25. #include <wx/event.h>
  26. #include <kiway_player.h>
  27. wxDEFINE_EVENT( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, wxCommandEvent );
  28. DIALOG_BOOK_REPORTER::DIALOG_BOOK_REPORTER( KIWAY_PLAYER* aParent, const wxString& aName,
  29. const wxString& aTitle ) :
  30. DIALOG_BOOK_REPORTER_BASE( aParent, wxID_ANY, aTitle ),
  31. m_frame( aParent )
  32. {
  33. SetName( aName );
  34. SetupStandardButtons();
  35. finishDialogSettings();
  36. }
  37. void DIALOG_BOOK_REPORTER::DeleteAllPages()
  38. {
  39. m_notebook->DeleteAllPages();
  40. }
  41. void DIALOG_BOOK_REPORTER::OnErrorLinkClicked( wxHtmlLinkEvent& aEvent )
  42. {
  43. m_frame->ExecuteRemoteCommand( aEvent.GetLinkInfo().GetHref().ToStdString().c_str() );
  44. }
  45. WX_HTML_REPORT_BOX* DIALOG_BOOK_REPORTER::AddHTMLPage( const wxString& aTitle )
  46. {
  47. wxPanel* panel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  48. wxTAB_TRAVERSAL );
  49. wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
  50. WX_HTML_REPORT_BOX* reporter = new WX_HTML_REPORT_BOX( panel, wxID_ANY, wxDefaultPosition,
  51. wxDefaultSize,
  52. wxHW_SCROLLBAR_AUTO | wxBORDER_SIMPLE );
  53. sizer->Add( reporter, 1, wxEXPAND | wxALL, 5 );
  54. panel->SetSizer( sizer );
  55. panel->Layout();
  56. m_notebook->AddPage( panel, aTitle );
  57. reporter->SetUnits( m_frame->GetUserUnits() );
  58. reporter->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
  59. wxHtmlLinkEventHandler( DIALOG_BOOK_REPORTER::OnErrorLinkClicked ),
  60. nullptr, this );
  61. return reporter;
  62. }
  63. wxPanel* DIALOG_BOOK_REPORTER::AddBlankPage( const wxString& aTitle )
  64. {
  65. wxPanel* panel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  66. wxTAB_TRAVERSAL );
  67. m_notebook->AddPage( panel, aTitle );
  68. return panel;
  69. }
  70. int DIALOG_BOOK_REPORTER::GetPageCount() const
  71. {
  72. return m_notebook->GetPageCount();
  73. }
  74. void DIALOG_BOOK_REPORTER::OnClose( wxCloseEvent& aEvent )
  75. {
  76. // Dialog is mode-less so let the parent know that it needs to be destroyed.
  77. if( !IsModal() && !IsQuasiModal() )
  78. {
  79. wxCommandEvent* evt = new wxCommandEvent( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, wxID_ANY );
  80. evt->SetEventObject( this );
  81. evt->SetString( GetName() );
  82. wxWindow* parent = GetParent();
  83. if( parent )
  84. wxQueueEvent( parent, evt );
  85. }
  86. aEvent.Skip();
  87. }