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-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 
30 #include <wx/stockitem.h>
31 
32 #include <bitmaps.h>
33 #include <html_messagebox.h>
34 #include <dialog_exit_base.h>
35 
36 
38 {
39 public:
40  DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) :
41  DIALOG_EXIT_BASE( aParent )
42  {
43  m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) );
44 
45  if( !aMessage.IsEmpty() )
46  m_TextInfo->SetLabel( aMessage );
47 
48  GetSizer()->Fit( this );
49  GetSizer()->SetSizeHints( this );
50  };
51 
52 private:
53  void OnSaveAndExit( wxCommandEvent& event ) override { EndModal( wxID_YES ); }
54  void OnExitNoSave( wxCommandEvent& event ) override { EndModal( wxID_NO ); }
55 };
56 
57 
58 int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
59 {
60  DIALOG_EXIT dlg( parent, aMessage );
61 
62  int ret = dlg.ShowModal();
63 
64  // Returns wxID_YES, wxID_NO, or wxID_CANCEL
65  return ret;
66 }
67 
68 
69 void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
70 {
71  wxMessageDialog* dialog;
72 
73  if( displaytime > 0 )
74  dialog = new wxMessageDialog( parent, text, _( "Warning" ),
75  wxOK | wxCENTRE | wxICON_INFORMATION
76  | wxRESIZE_BORDER
77  );
78  else
79  dialog = new wxMessageDialog( parent, text, _( "Error" ),
80  wxOK | wxCENTRE | wxICON_ERROR
81  | wxRESIZE_BORDER
82  );
83 
84  dialog->ShowModal();
85  dialog->Destroy();
86 }
87 
88 
89 void DisplayInfoMessage( wxWindow* parent, const wxString& text, int displaytime )
90 {
91  wxMessageDialog* dialog;
92 
93  dialog = new wxMessageDialog( parent, text, _( "Info" ),
94  wxOK | wxCENTRE | wxICON_INFORMATION );
95 
96  dialog->ShowModal();
97  dialog->Destroy();
98 }
99 
100 
101 void DisplayHtmlInfoMessage( wxWindow* parent, const wxString& title,
102  const wxString& text, const wxSize& size )
103 {
104  HTML_MESSAGE_BOX dlg( parent, title, wxDefaultPosition, size );
105 
106  dlg.AddHTML_Text( text );
107  dlg.ShowModal();
108 }
109 
110 
111 bool IsOK( wxWindow* aParent, const wxString& aMessage )
112 {
113  wxMessageDialog dlg( aParent, aMessage, _( "Confirmation" ),
114  wxYES_NO | wxCENTRE | wxICON_QUESTION );
115 
116  return dlg.ShowModal() == wxID_YES;
117 }
118 
119 
121 {
122 public:
123  DIALOG_YES_NO_CANCEL( wxWindow *aParent,
124  const wxString& aPrimaryMessage,
125  const wxString& aSecondaryMessage = wxEmptyString,
126  const wxString& aYesButtonText = wxEmptyString,
127  const wxString& aNoButtonText = wxEmptyString,
128  const wxString& aCancelButtonText = wxEmptyString ) :
129  DIALOG_EXIT( aParent, aSecondaryMessage )
130  {
131  m_TextInfo->SetLabel( aPrimaryMessage );
132 
133  if( aSecondaryMessage.IsEmpty() )
134  m_staticText2->Hide();
135 
136  m_buttonSaveAndExit->SetLabel( aYesButtonText.IsEmpty() ? wxGetStockLabel( wxID_YES ) :
137  aYesButtonText );
138  m_buttonExitNoSave->SetLabel( aNoButtonText.IsEmpty() ? wxGetStockLabel( wxID_NO ) :
139  aNoButtonText );
140  m_buttonCancel->SetLabel( aCancelButtonText.IsEmpty() ? wxGetStockLabel( wxID_CANCEL ) :
141  aCancelButtonText );
142  GetSizer()->Fit( this );
143  GetSizer()->SetSizeHints( this );
144  };
145 };
146 
147 
148 int YesNoCancelDialog( wxWindow* aParent,
149  const wxString& aPrimaryMessage,
150  const wxString& aSecondaryMessage,
151  const wxString& aYesButtonText,
152  const wxString& aNoButtonText,
153  const wxString& aCancelButtonText )
154 {
155  DIALOG_YES_NO_CANCEL dlg( aParent, aPrimaryMessage, aSecondaryMessage,
156  aYesButtonText, aNoButtonText, aCancelButtonText );
157 
158  return dlg.ShowModal();
159 }
DIALOG_EXIT(wxWindow *aParent, const wxString &aMessage)
Definition: confirm.cpp:40
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:123
void OnExitNoSave(wxCommandEvent &event) override
Definition: confirm.cpp:54
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
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
Class HTML_MESSAGE_BOX.
wxButton * m_buttonCancel
wxStaticBitmap * m_bitmap
void DisplayInfoMessage(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:89
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:58
void DisplayHtmlInfoMessage(wxWindow *parent, const wxString &title, const wxString &text, const wxSize &size)
Function DisplayHtmlInforMessage displays aMessage in HTML format.
Definition: confirm.cpp:101
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:69
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:148
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
wxStaticText * m_staticText2
void OnSaveAndExit(wxCommandEvent &event) override
Definition: confirm.cpp:53