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.

160 lines
5.3 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file confirm.cpp
  26. * @brief utilities to display some error, warning and info short messges
  27. */
  28. #include <fctsys.h>
  29. #include <common.h>
  30. #include <wx/wx.h>
  31. #include <wx/html/htmlwin.h>
  32. #include <wx/stockitem.h>
  33. #include <html_messagebox.h>
  34. #include <dialog_exit_base.h>
  35. #include <bitmaps.h>
  36. class DIALOG_EXIT: public DIALOG_EXIT_BASE
  37. {
  38. public:
  39. DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) :
  40. DIALOG_EXIT_BASE( aParent )
  41. {
  42. m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) );
  43. if( !aMessage.IsEmpty() )
  44. m_TextInfo->SetLabel( aMessage );
  45. GetSizer()->Fit( this );
  46. GetSizer()->SetSizeHints( this );
  47. };
  48. private:
  49. void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_YES ); }
  50. void OnCancel( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); }
  51. void OnExitNoSave( wxCommandEvent& event ) { EndModal( wxID_NO ); }
  52. };
  53. int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
  54. {
  55. DIALOG_EXIT dlg( parent, aMessage );
  56. int ret = dlg.ShowModal();
  57. return ret;
  58. }
  59. void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
  60. {
  61. wxMessageDialog* dialog;
  62. if( displaytime > 0 )
  63. dialog = new wxMessageDialog( parent, text, _( "Warning" ),
  64. wxOK | wxCENTRE | wxICON_INFORMATION
  65. | wxRESIZE_BORDER
  66. );
  67. else
  68. dialog = new wxMessageDialog( parent, text, _( "Error" ),
  69. wxOK | wxCENTRE | wxICON_ERROR
  70. | wxRESIZE_BORDER
  71. );
  72. dialog->ShowModal();
  73. dialog->Destroy();
  74. }
  75. void DisplayInfoMessage( wxWindow* parent, const wxString& text, int displaytime )
  76. {
  77. wxMessageDialog* dialog;
  78. dialog = new wxMessageDialog( parent, text, _( "Info" ),
  79. wxOK | wxCENTRE | wxICON_INFORMATION );
  80. dialog->ShowModal();
  81. dialog->Destroy();
  82. }
  83. void DisplayHtmlInfoMessage( wxWindow* parent, const wxString& title,
  84. const wxString& text, const wxSize& size )
  85. {
  86. HTML_MESSAGE_BOX dlg( parent, title, wxDefaultPosition, size );
  87. dlg.AddHTML_Text( text );
  88. dlg.ShowModal();
  89. }
  90. bool IsOK( wxWindow* aParent, const wxString& aMessage )
  91. {
  92. wxMessageDialog dlg( aParent, aMessage, _( "Confirmation" ),
  93. wxYES_NO | wxCENTRE | wxICON_HAND );
  94. return dlg.ShowModal() == wxID_YES;
  95. }
  96. class DIALOG_YES_NO_CANCEL : public DIALOG_EXIT
  97. {
  98. public:
  99. DIALOG_YES_NO_CANCEL( wxWindow *aParent,
  100. const wxString& aPrimaryMessage,
  101. const wxString& aSecondaryMessage = wxEmptyString,
  102. const wxString& aYesButtonText = wxEmptyString,
  103. const wxString& aNoButtonText = wxEmptyString,
  104. const wxString& aCancelButtonText = wxEmptyString ) :
  105. DIALOG_EXIT( aParent, aSecondaryMessage )
  106. {
  107. m_TextInfo->SetLabel( aPrimaryMessage );
  108. if( aSecondaryMessage.IsEmpty() )
  109. m_staticText2->Hide();
  110. m_buttonSaveAndExit->SetLabel( aYesButtonText.IsEmpty() ? wxGetStockLabel( wxID_YES ) :
  111. aYesButtonText );
  112. m_buttonExitNoSave->SetLabel( aNoButtonText.IsEmpty() ? wxGetStockLabel( wxID_NO ) :
  113. aNoButtonText );
  114. m_buttonCancel->SetLabel( aCancelButtonText.IsEmpty() ? wxGetStockLabel( wxID_CANCEL ) :
  115. aCancelButtonText );
  116. GetSizer()->Fit( this );
  117. GetSizer()->SetSizeHints( this );
  118. };
  119. };
  120. int YesNoCancelDialog( wxWindow* aParent,
  121. const wxString& aPrimaryMessage,
  122. const wxString& aSecondaryMessage,
  123. const wxString& aYesButtonText,
  124. const wxString& aNoButtonText,
  125. const wxString& aCancelButtonText )
  126. {
  127. DIALOG_YES_NO_CANCEL dlg( aParent, aPrimaryMessage, aSecondaryMessage,
  128. aYesButtonText, aNoButtonText, aCancelButtonText );
  129. return dlg.ShowModal();
  130. }