KiCad PCB EDA Suite
confirm.cpp
Go to the documentation of this file.
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-2017 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 
30 #include <wx/stockitem.h>
31 #include <wx/richmsgdlg.h>
32 
33 #include <bitmaps.h>
34 #include <html_messagebox.h>
35 #include <dialog_exit_base.h>
36 
37 
39 {
40 public:
41  DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) :
42  DIALOG_EXIT_BASE( aParent )
43  {
44  m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) );
45 
46  if( !aMessage.IsEmpty() )
47  m_TextInfo->SetLabel( aMessage );
48 
49  GetSizer()->Fit( this );
50  GetSizer()->SetSizeHints( this );
51  };
52 
53 private:
54  void OnSaveAndExit( wxCommandEvent& event ) override { EndModal( wxID_YES ); }
55  void OnExitNoSave( wxCommandEvent& event ) override { EndModal( wxID_NO ); }
56 };
57 
58 
59 int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
60 {
61  DIALOG_EXIT dlg( parent, aMessage );
62 
63  int ret = dlg.ShowModal();
64 
65  // Returns wxID_YES, wxID_NO, or wxID_CANCEL
66  return ret;
67 }
68 
69 
70 // DisplayError should be deprecated, use DisplayErrorMessage instead
71 void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
72 {
73  wxMessageDialog* dialog;
74 
75  int icon = displaytime > 0 ? wxICON_INFORMATION : wxICON_ERROR;
76 
77  dialog = new wxMessageDialog( parent, text, _( "Warning" ),
78  wxOK | wxCENTRE | wxRESIZE_BORDER | icon );
79 
80  dialog->ShowModal();
81  dialog->Destroy();
82 }
83 
84 
85 void DisplayErrorMessage( wxWindow* aParent, const wxString& aText, const wxString aExtraInfo )
86 {
87  wxRichMessageDialog* dlg;
88 
89  dlg = new wxRichMessageDialog( aParent, aText, _( "Error" ),
90  wxOK | wxCENTRE | wxRESIZE_BORDER | wxICON_ERROR );
91 
92  if( !aExtraInfo.IsEmpty() )
93  {
94  dlg->ShowDetailedText( aExtraInfo );
95  }
96 
97  dlg->ShowModal();
98  dlg->Destroy();
99 }
100 
101 
102 void DisplayInfoMessage( wxWindow* aParent, const wxString& aMessage, const wxString aExtraInfo )
103 {
104  wxRichMessageDialog* dlg;
105 
106  dlg = new wxRichMessageDialog( aParent, aMessage, _( "Info" ),
107  wxOK | wxCENTRE | wxRESIZE_BORDER | wxICON_INFORMATION );
108 
109  if( !aExtraInfo.IsEmpty() )
110  {
111  dlg->ShowDetailedText( aExtraInfo );
112  }
113 
114  dlg->ShowModal();
115  dlg->Destroy();
116 }
117 
118 
119 void DisplayHtmlInfoMessage( wxWindow* parent, const wxString& title,
120  const wxString& text, const wxSize& size )
121 {
122  HTML_MESSAGE_BOX dlg( parent, title, wxDefaultPosition, size );
123 
124  dlg.AddHTML_Text( text );
125  dlg.ShowModal();
126 }
127 
128 
129 bool IsOK( wxWindow* aParent, const wxString& aMessage )
130 {
131  wxMessageDialog dlg( aParent, aMessage, _( "Confirmation" ),
132  wxYES_NO | wxCENTRE | wxICON_QUESTION );
133 
134  return dlg.ShowModal() == wxID_YES;
135 }
136 
137 
139 {
140 public:
141  DIALOG_YES_NO_CANCEL( wxWindow *aParent,
142  const wxString& aPrimaryMessage,
143  const wxString& aSecondaryMessage = wxEmptyString,
144  const wxString& aYesButtonText = wxEmptyString,
145  const wxString& aNoButtonText = wxEmptyString,
146  const wxString& aCancelButtonText = wxEmptyString ) :
147  DIALOG_EXIT( aParent, aSecondaryMessage )
148  {
149  m_TextInfo->SetLabel( aPrimaryMessage );
150 
151  if( aSecondaryMessage.IsEmpty() )
152  m_staticText2->Hide();
153 
154  m_buttonSaveAndExit->SetLabel( aYesButtonText.IsEmpty() ? wxGetStockLabel( wxID_YES ) :
155  aYesButtonText );
156  m_buttonExitNoSave->SetLabel( aNoButtonText.IsEmpty() ? wxGetStockLabel( wxID_NO ) :
157  aNoButtonText );
158  m_buttonCancel->SetLabel( aCancelButtonText.IsEmpty() ? wxGetStockLabel( wxID_CANCEL ) :
159  aCancelButtonText );
160  GetSizer()->Fit( this );
161  GetSizer()->SetSizeHints( this );
162  };
163 };
164 
165 
166 int YesNoCancelDialog( wxWindow* aParent,
167  const wxString& aPrimaryMessage,
168  const wxString& aSecondaryMessage,
169  const wxString& aYesButtonText,
170  const wxString& aNoButtonText,
171  const wxString& aCancelButtonText )
172 {
173  DIALOG_YES_NO_CANCEL dlg( aParent, aPrimaryMessage, aSecondaryMessage,
174  aYesButtonText, aNoButtonText, aCancelButtonText );
175 
176  return dlg.ShowModal();
177 }
DIALOG_EXIT(wxWindow *aParent, const wxString &aMessage)
Definition: confirm.cpp:41
DIALOG_YES_NO_CANCEL(wxWindow *aParent, const wxString &aPrimaryMessage, const wxString &aSecondaryMessage=wxEmptyString, const wxString &aYesButtonText=wxEmptyString, const wxString &aNoButtonText=wxEmptyString, const wxString &aCancelButtonText=wxEmptyString)
Definition: confirm.cpp:141
void OnExitNoSave(wxCommandEvent &event) override
Definition: confirm.cpp:55
wxStaticText * m_TextInfo
Class DIALOG_EXIT_BASE.
wxButton * m_buttonSaveAndExit
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:85
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:102
Class HTML_MESSAGE_BOX.
wxButton * m_buttonCancel
wxStaticBitmap * m_bitmap
int DisplayExitDialog(wxWindow *parent, const wxString &aMessage)
Function DisplayExitDialog displays a dialog with 3 buttons: Save and Exit Cancel Exit without save...
Definition: confirm.cpp:59
void DisplayHtmlInfoMessage(wxWindow *parent, const wxString &title, const wxString &text, const wxSize &size)
Function DisplayHtmlInforMessage displays aMessage in HTML format.
Definition: confirm.cpp:119
void AddHTML_Text(const wxString &message)
Function AddHTML_Text adds html text (without any change) to message list.
wxButton * m_buttonExitNoSave
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
int YesNoCancelDialog(wxWindow *aParent, const wxString &aPrimaryMessage, const wxString &aSecondaryMessage, const wxString &aYesButtonText, const wxString &aNoButtonText, const wxString &aCancelButtonText)
Function YesNoCancelDialog displays a yes/no/cancel dialog with aMessage and returns the user respons...
Definition: confirm.cpp:166
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:129
wxStaticText * m_staticText2
void OnSaveAndExit(wxCommandEvent &event) override
Definition: confirm.cpp:54