confirm.cpp 5.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.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
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

25
/**
26
 * @file confirm.cpp
27
 * @brief utilities to display some error, warning and info short messges
28
 */
plyatov's avatar
plyatov committed
29

30 31 32 33
#include <fctsys.h>
#include <common.h>
#include <wx/wx.h>
#include <wx/html/htmlwin.h>
34
#include <wx/stockitem.h>
35
#include <html_messagebox.h>
36 37
#include <dialog_exit_base.h>
#include <bitmaps.h>
dickelbeck's avatar
dickelbeck committed
38

39 40 41
class DIALOG_EXIT: public DIALOG_EXIT_BASE
{
public:
42 43
    DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) :
        DIALOG_EXIT_BASE( aParent )
44
    {
45
        m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) );
46 47

        if( !aMessage.IsEmpty() )
48
            m_TextInfo->SetLabel( aMessage );
49

50 51 52 53 54
        GetSizer()->Fit( this );
        GetSizer()->SetSizeHints( this );
    };

private:
55 56 57
    void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_YES ); }
    void OnCancel( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); }
    void OnExitNoSave( wxCommandEvent& event ) { EndModal( wxID_NO ); }
58 59
};

60

61 62 63 64 65 66 67
int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
{
    DIALOG_EXIT dlg( parent, aMessage );

    int ret = dlg.ShowModal();
    return ret;
}
68

69

70
void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
plyatov's avatar
plyatov committed
71
{
dickelbeck's avatar
dickelbeck committed
72 73 74
    wxMessageDialog* dialog;

    if( displaytime > 0 )
75
        dialog = new wxMessageDialog( parent, text, _( "Warning" ),
76 77 78
                                      wxOK | wxCENTRE | wxICON_INFORMATION
                                      | wxRESIZE_BORDER
                                      );
dickelbeck's avatar
dickelbeck committed
79
    else
80
        dialog = new wxMessageDialog( parent, text, _( "Error" ),
81 82 83
                                      wxOK | wxCENTRE | wxICON_ERROR
                                      | wxRESIZE_BORDER
                                      );
dickelbeck's avatar
dickelbeck committed
84 85 86

    dialog->ShowModal();
    dialog->Destroy();
plyatov's avatar
plyatov committed
87 88
}

dickelbeck's avatar
dickelbeck committed
89

90
void DisplayInfoMessage( wxWindow* parent, const wxString& text, int displaytime )
plyatov's avatar
plyatov committed
91
{
dickelbeck's avatar
dickelbeck committed
92
    wxMessageDialog* dialog;
plyatov's avatar
plyatov committed
93

94
    dialog = new wxMessageDialog( parent, text, _( "Info" ),
95
                                  wxOK | wxCENTRE | wxICON_INFORMATION );
plyatov's avatar
plyatov committed
96

97 98
    dialog->ShowModal();
    dialog->Destroy();
plyatov's avatar
plyatov committed
99 100 101
}


102 103 104
void DisplayHtmlInfoMessage( wxWindow* parent, const wxString& title,
                             const wxString& text, const wxSize& size )
{
105 106 107 108
    HTML_MESSAGE_BOX dlg( parent, title, wxDefaultPosition, size );

    dlg.AddHTML_Text( text );
    dlg.ShowModal();
109 110 111
}


112 113 114 115 116
bool IsOK( wxWindow* aParent, const wxString& aMessage )
{
    wxMessageDialog dlg( aParent, aMessage, _( "Confirmation" ),
                         wxYES_NO | wxCENTRE | wxICON_HAND );

117
    return dlg.ShowModal() == wxID_YES;
118 119 120 121
}


class DIALOG_YES_NO_CANCEL : public DIALOG_EXIT
plyatov's avatar
plyatov committed
122
{
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
public:
    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 ) :
        DIALOG_EXIT( aParent, aSecondaryMessage )
    {
        m_TextInfo->SetLabel( aPrimaryMessage );

        if( aSecondaryMessage.IsEmpty() )
            m_staticText2->Hide();

        m_buttonSaveAndExit->SetLabel( aYesButtonText.IsEmpty() ? wxGetStockLabel( wxID_YES ) :
                                       aYesButtonText );
        m_buttonExitNoSave->SetLabel( aNoButtonText.IsEmpty() ? wxGetStockLabel( wxID_NO ) :
                                      aNoButtonText );
        m_buttonCancel->SetLabel( aCancelButtonText.IsEmpty() ? wxGetStockLabel( wxID_CANCEL ) :
                                  aCancelButtonText );
        GetSizer()->Fit( this );
        GetSizer()->SetSizeHints( this );
    };
};
dickelbeck's avatar
dickelbeck committed
147

148

149 150 151 152 153 154 155 156 157
int YesNoCancelDialog( wxWindow*       aParent,
                       const wxString& aPrimaryMessage,
                       const wxString& aSecondaryMessage,
                       const wxString& aYesButtonText,
                       const wxString& aNoButtonText,
                       const wxString& aCancelButtonText )
{
    DIALOG_YES_NO_CANCEL dlg( aParent, aPrimaryMessage, aSecondaryMessage,
                              aYesButtonText, aNoButtonText, aCancelButtonText );
plyatov's avatar
plyatov committed
158

159
    return dlg.ShowModal();
160
}