kicad/common/confirm.cpp

160 lines
4.7 KiB
C++
Raw Normal View History

2007-12-05 20:54:11 +00:00
/*************************/
/* Menu " CONFIRMATION " */
/* fonction Get_Message */
/* test demande ESC */
/*************************/
2007-05-06 16:03:28 +00:00
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "fctsys.h"
#include "common.h"
enum id_dialog {
2007-12-05 20:54:11 +00:00
ID_TIMOUT = 1500
2007-05-06 16:03:28 +00:00
};
/* Classe d'affichage de messages, identique a wxMessageDialog,
2007-12-05 20:54:11 +00:00
* mais pouvant etre effacee au bout d'un time out donne
*/
class WinEDA_MessageDialog : public wxMessageDialog
2007-05-06 16:03:28 +00:00
{
public:
2007-12-05 20:54:11 +00:00
int m_LifeTime;
2007-05-06 16:03:28 +00:00
private:
2007-12-05 20:54:11 +00:00
wxTimer m_Timer;
2007-05-06 16:03:28 +00:00
public:
2007-12-05 20:54:11 +00:00
WinEDA_MessageDialog( wxWindow * parent, const wxString &msg,
const wxString &title, int style, int lifetime );
~WinEDA_MessageDialog() { };
2007-05-06 16:03:28 +00:00
2007-12-05 20:54:11 +00:00
void OnTimeOut( wxTimerEvent& event );
DECLARE_EVENT_TABLE()
2007-05-06 16:03:28 +00:00
};
2007-12-05 20:54:11 +00:00
BEGIN_EVENT_TABLE( WinEDA_MessageDialog, wxMessageDialog )
EVT_TIMER( ID_TIMOUT, WinEDA_MessageDialog::OnTimeOut )
2007-05-06 16:03:28 +00:00
END_EVENT_TABLE()
/**********************************************************************************/
2007-12-05 20:54:11 +00:00
WinEDA_MessageDialog::WinEDA_MessageDialog( wxWindow* parent, const wxString& msg,
const wxString& title, int style, int lifetime ) :
wxMessageDialog( parent, msg, title, style )
2007-05-06 16:03:28 +00:00
/**********************************************************************************/
{
2007-12-05 20:54:11 +00:00
m_LifeTime = lifetime;
m_Timer.SetOwner( this, ID_TIMOUT );
if( m_LifeTime > 0 )
m_Timer.Start( 100 * m_LifeTime, wxTIMER_ONE_SHOT ); // m_LifeTime = duree en 0.1 secondes
2007-05-06 16:03:28 +00:00
}
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/********************************************************/
2007-12-05 20:54:11 +00:00
void WinEDA_MessageDialog::OnTimeOut( wxTimerEvent& event )
2007-05-06 16:03:28 +00:00
/********************************************************/
{
2007-12-05 20:54:11 +00:00
// TODO : EndModal() request
2007-05-06 16:03:28 +00:00
}
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/*****************************************************************************/
2007-12-05 20:54:11 +00:00
void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
2007-05-06 16:03:28 +00:00
/*****************************************************************************/
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/* Affiche un Message d'Erreur ou d'avertissement.
2007-12-05 20:54:11 +00:00
* si warn > 0 le dialogue disparait apres warn 0.1 secondes
*/
2007-05-06 16:03:28 +00:00
{
2007-12-05 20:54:11 +00:00
wxMessageDialog* dialog;
if( displaytime > 0 )
dialog = new WinEDA_MessageDialog( parent, text, _(
"Warning" ),
wxOK | wxICON_INFORMATION | wxSTAY_ON_TOP,
displaytime );
else
dialog = new WinEDA_MessageDialog( parent, text, _( "Error" ),
wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP, 0 );
dialog->ShowModal();
dialog->Destroy();
2007-05-06 16:03:28 +00:00
}
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/**************************************************************************/
2007-12-05 20:54:11 +00:00
void DisplayInfo( wxWindow* parent, const wxString& text, int displaytime )
2007-05-06 16:03:28 +00:00
/**************************************************************************/
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/* Affiche un Message d'information.
2007-12-05 20:54:11 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-12-05 20:54:11 +00:00
wxMessageDialog* dialog;
2007-05-06 16:03:28 +00:00
2007-12-05 20:54:11 +00:00
dialog = new WinEDA_MessageDialog( parent, text, _( "Infos:" ),
wxOK | wxICON_INFORMATION | wxSTAY_ON_TOP, displaytime );
2007-05-06 16:03:28 +00:00
2007-12-05 20:54:11 +00:00
dialog->ShowModal(); dialog->Destroy();
2007-05-06 16:03:28 +00:00
}
/**************************************************/
2007-12-05 20:54:11 +00:00
bool IsOK( wxWindow* parent, const wxString& text )
2007-05-06 16:03:28 +00:00
/**************************************************/
{
2007-12-05 20:54:11 +00:00
int ii;
ii = wxMessageBox( text, _( "Confirmation" ), wxYES_NO | wxCENTRE | wxICON_HAND, parent );
if( ii == wxYES )
return TRUE;
return FALSE;
2007-05-06 16:03:28 +00:00
}
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/***********************************************************************/
int Get_Message( const wxString& title, // The question
const wxString& frame_caption, // The frame caption
wxString& buffer, // String input buffer
wxWindow* frame )
2007-05-06 16:03:28 +00:00
/***********************************************************************/
2007-12-05 20:54:11 +00:00
2007-05-06 16:03:28 +00:00
/* Get a text from user
2007-12-05 20:54:11 +00:00
* titre = titre a afficher
* buffer : text enter by user
* leading and trailing spaces are removed
* if buffer != "" buffer is displayed
* return:
* 0 if OK
* != 0 if ESCAPE
*/
2007-05-06 16:03:28 +00:00
{
2007-12-05 20:54:11 +00:00
wxString message, default_text;
if( buffer )
default_text = buffer;
message = wxGetTextFromUser( title, frame_caption,
2007-12-05 20:54:11 +00:00
default_text, frame );
if( !message.IsEmpty() )
{
message.Trim( FALSE ); // Remove blanks at beginning
message.Trim( TRUE ); // Remove blanks at end
buffer = message;
return 0;
}
return 1;
2007-05-06 16:03:28 +00:00
}