File: confirm.cpp

package info (click to toggle)
kicad 0.0.20060829-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 56,544 kB
  • ctags: 9,194
  • sloc: cpp: 88,990; ansic: 4,790; makefile: 88; sh: 39
file content (145 lines) | stat: -rw-r--r-- 4,086 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
	/*************************/
	/* Menu " CONFIRMATION " */
	/* fonction Get_Message	 */
	/* test demande ESC 	 */
	/*************************/

// 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 {
	ID_TIMOUT = 1500
};

/* Classe d'affichage de messages, identique a wxMessageDialog,
	mais pouvant etre effacee au bout d'un time out donne
*/
class WinEDA_MessageDialog: public wxMessageDialog
{
public:
	int m_LifeTime;
private:
	wxTimer m_Timer;

public:
	WinEDA_MessageDialog(wxWindow * parent, const wxString & msg,
			const wxString & title, int style, int lifetime);
	~WinEDA_MessageDialog(){};

	void OnTimeOut(wxTimerEvent& event);
	DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(WinEDA_MessageDialog, wxMessageDialog)
	EVT_TIMER(ID_TIMOUT, WinEDA_MessageDialog::OnTimeOut)
END_EVENT_TABLE()

/**********************************************************************************/
WinEDA_MessageDialog::WinEDA_MessageDialog(wxWindow * parent, const wxString & msg,
			const wxString & title, int style, int lifetime) :
			wxMessageDialog(parent, msg, title, style)
/**********************************************************************************/
{
	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
}

/********************************************************/
void WinEDA_MessageDialog::OnTimeOut(wxTimerEvent& event)
/********************************************************/
{
	//	TODO : EndModal() request
}

/*****************************************************************************/
void DisplayError(wxWindow * parent,  const wxString & text, int displaytime )
/*****************************************************************************/
/*  Affiche un Message d'Erreur ou d'avertissement.
	si warn > 0 le dialogue disparait apres warn 0.1 secondes
*/
{
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();
}

/**************************************************************************/
void DisplayInfo(wxWindow * parent, const wxString & text, int displaytime)
/**************************************************************************/
/* Affiche un Message d'information.
*/

{
wxMessageDialog * dialog;

	dialog = new WinEDA_MessageDialog(parent, text, _("Infos:"),
			wxOK | wxICON_INFORMATION | wxSTAY_ON_TOP, displaytime);

	dialog->ShowModal(); dialog->Destroy();
}


/**************************************************/
bool IsOK(wxWindow * parent, const wxString & text)
/**************************************************/
{
int ii;
	ii = wxMessageBox(text, _("Confirmation"), wxYES_NO|wxCENTRE|wxICON_HAND, parent);
	if (ii == wxYES) return TRUE;
	return FALSE;
}

/***********************************************************************/
int Get_Message(const wxString & title, wxString & buffer, wxWindow * frame)
/***********************************************************************/
/* Get a text from user
	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
*/
{
wxString message, default_text;

	if ( buffer ) default_text = buffer;

	message = wxGetTextFromUser(title, _("Text:"),
				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);
}