From a994f81b947bd6ec0e7611988b3ebc1ae3e9df5a Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Thu, 25 Feb 1999 14:47:18 +0000
Subject: [PATCH] 1. validator fixes: don't eat TAB. Added new SetBellOnError()
 function to    suppress _annoying_ bell. 2. Docs and samples updated to
 reflect this.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1791 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/validatr.tex    |   7 +
 include/wx/gtk/listbox.h      |   2 +
 include/wx/gtk1/listbox.h     |   2 +
 include/wx/validate.h         |  57 +++--
 samples/validate/validate.cpp |  72 ++++---
 samples/validate/validate.h   |  30 +--
 src/common/validate.cpp       |  16 +-
 src/common/valtext.cpp        | 395 ++++++++++++++++------------------
 8 files changed, 306 insertions(+), 275 deletions(-)

diff --git a/docs/latex/wx/validatr.tex b/docs/latex/wx/validatr.tex
index 2bbb2f7dd3..b6319b0a39 100644
--- a/docs/latex/wx/validatr.tex
+++ b/docs/latex/wx/validatr.tex
@@ -64,6 +64,13 @@ This base function returns NULL.
 
 Returns the window associated with the validator.
 
+\membersection{wxValidator::SetBellOnError}{wxvalidatorsetbellonerror}
+
+\func{void}{SetBellOnError}{\param{bool}{ doIt = TRUE}}
+
+This functions switches on or turns off the error sound produced by the
+validators if an invalid key is pressed.
+
 \membersection{wxValidator::SetWindow}\label{wxvalidatorsetwindow}
 
 \func{void}{SetWindow}{\param{wxWindow*}{ window}}
diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h
index 2a5f428da1..6fa8de11cd 100644
--- a/include/wx/gtk/listbox.h
+++ b/include/wx/gtk/listbox.h
@@ -68,6 +68,8 @@ public:
     void Append( const wxString &item, void* clientData );
     void Append( const wxString &item, wxClientData* clientData );
 
+    void InsertItems(int nItems, const wxString items[], int pos);
+
     void SetClientData( int n, void* clientData );
     void* GetClientData( int n );
     void SetClientObject( int n, wxClientData* clientData );
diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h
index 2a5f428da1..6fa8de11cd 100644
--- a/include/wx/gtk1/listbox.h
+++ b/include/wx/gtk1/listbox.h
@@ -68,6 +68,8 @@ public:
     void Append( const wxString &item, void* clientData );
     void Append( const wxString &item, wxClientData* clientData );
 
+    void InsertItems(int nItems, const wxString items[], int pos);
+
     void SetClientData( int n, void* clientData );
     void* GetClientData( int n );
     void SetClientObject( int n, wxClientData* clientData );
diff --git a/include/wx/validate.h b/include/wx/validate.h
index a67d9cba9b..1cb97fe604 100644
--- a/include/wx/validate.h
+++ b/include/wx/validate.h
@@ -6,14 +6,14 @@
 // Created:     29/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998 Julian Smart
-// Licence:   	wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifndef _WX_VALIDATEH__
 #define _WX_VALIDATEH__
 
 #ifdef __GNUG__
-#pragma interface "validate.h"
+    #pragma interface "validate.h"
 #endif
 
 #include "wx/event.h"
@@ -30,38 +30,49 @@ class WXDLLEXPORT wxWindow;
     to intercept e.g. OnChar.
 
  Note that wxValidator and derived classes use reference counting.
- */
+*/
 
-class WXDLLEXPORT wxValidator: public wxEvtHandler
+class WXDLLEXPORT wxValidator : public wxEvtHandler
 {
-DECLARE_DYNAMIC_CLASS(wxValidator)
 public:
-  wxValidator(void);
-  ~wxValidator();
+    wxValidator();
+    ~wxValidator();
 
-  // Make a clone of this validator (or return NULL) - currently necessary
-  // if you're passing a reference to a validator.
-  // Another possibility is to always pass a pointer to a new validator
-  // (so the calling code can use a copy constructor of the relevant class).
-  virtual wxValidator *Clone(void) const { return (wxValidator *) NULL; }
-  inline bool Copy(const wxValidator& val) { m_validatorWindow = val.m_validatorWindow; return TRUE; }
+    // Make a clone of this validator (or return NULL) - currently necessary
+    // if you're passing a reference to a validator.
+    // Another possibility is to always pass a pointer to a new validator
+    // (so the calling code can use a copy constructor of the relevant class).
+    virtual wxValidator *Clone() const
+        { return (wxValidator *)NULL; }
+    bool Copy(const wxValidator& val)
+        { m_validatorWindow = val.m_validatorWindow; return TRUE; }
 
-  // Called when the value in the window must be validated.
-  // This function can pop up an error message.
-  virtual bool Validate(wxWindow *WXUNUSED(parent)) { return FALSE; };
+    // Called when the value in the window must be validated.
+    // This function can pop up an error message.
+    virtual bool Validate(wxWindow *WXUNUSED(parent)) { return FALSE; };
 
-  // Called to transfer data to the window
-  virtual bool TransferToWindow(void) { return FALSE; }
+    // Called to transfer data to the window
+    virtual bool TransferToWindow() { return FALSE; }
 
-  // Called to transfer data from the window
-  virtual bool TransferFromWindow(void) { return FALSE; };
+    // Called to transfer data from the window
+    virtual bool TransferFromWindow() { return FALSE; };
 
-  // ACCESSORS
-  inline wxWindow *GetWindow(void) const { return m_validatorWindow; }
-  inline void SetWindow(wxWindow *win) { m_validatorWindow = win; }
+    // accessors
+    wxWindow *GetWindow() const { return m_validatorWindow; }
+    void SetWindow(wxWindow *win) { m_validatorWindow = win; }
+
+    // validators beep by default if invalid key is pressed, these functions
+    // allow to change it
+    static bool IsSilent() { return ms_isSilent; }
+    static void SetBellOnError(bool doIt = TRUE) { ms_isSilent = doIt; }
 
 protected:
     wxWindow *m_validatorWindow;
+
+private:
+    static bool ms_isSilent;
+
+    DECLARE_DYNAMIC_CLASS(wxValidator)
 };
 
 WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator;
diff --git a/samples/validate/validate.cpp b/samples/validate/validate.cpp
index 334150af31..6049dac8ca 100644
--- a/samples/validate/validate.cpp
+++ b/samples/validate/validate.cpp
@@ -6,7 +6,7 @@
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:   	wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
@@ -30,66 +30,82 @@
 #include "validate.h"
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
-	EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
-	EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog)
+    EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
+    EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog)
+    EVT_MENU(VALIDATE_SILENT, MyFrame::OnSilent)
 END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
 
-MyData	g_data;
+MyData g_data;
 
-bool MyApp::OnInit(void)
+bool MyApp::OnInit()
 {
   // Create the main frame window
-  MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Validation Test", 50, 50, 300, 250);
+  MyFrame *frame = new MyFrame((wxFrame *) NULL, "Validation Test", 50, 50, 300, 250);
 
+  // Show the frame
+  frame->Show(TRUE);
+
+  SetTopWindow(frame);
+
+  return TRUE;
+}
+
+// My frame constructor
+MyFrame::MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h)
+       : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
+{
   // Give it an icon
 #ifdef __WXMSW__
-  frame->SetIcon(wxIcon("mondrian"));
+  SetIcon(wxIcon("mondrian"));
 #endif
 #ifdef __X__
-  frame->SetIcon(wxIcon("aiai.xbm"));
+  SetIcon(wxIcon("aiai.xbm"));
 #endif
 
   // Make a menubar
   wxMenu *file_menu = new wxMenu;
 
-  file_menu->Append(VALIDATE_TEST_DIALOG, "&Test dialog");
+  file_menu->Append(VALIDATE_TEST_DIALOG, "&Test dialog", "Show example dialog");
+  file_menu->Append(VALIDATE_SILENT, "&Bell on error", "Toggle bell on error", TRUE);
+  file_menu->AppendSeparator();
   file_menu->Append(wxID_EXIT, "E&xit");
-  wxMenuBar *menu_bar = new wxMenuBar;
-  menu_bar->Append(file_menu, "File");
-  frame->SetMenuBar(menu_bar);
-
-  frame->CreateStatusBar(1);
 
-  // Show the frame
-  frame->Show(TRUE);
+  file_menu->Check(VALIDATE_SILENT, wxValidator::IsSilent());
 
-  SetTopWindow(frame);
+  wxMenuBar *menu_bar = new wxMenuBar;
+  menu_bar->Append(file_menu, "File");
+  SetMenuBar(menu_bar);
 
-  return TRUE;  
+  CreateStatusBar(1);
 }
 
-// My frame constructor
-MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
-  wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
-{}
-
 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 {
-  Close(TRUE);
+    Close(TRUE);
 }
 
 void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
 {
-	MyDialog dialog(this, "Validation test dialog", wxPoint(100, 100), wxSize(340, 170));
+    MyDialog dialog(this, "Validation test dialog", wxPoint(100, 100), wxSize(340, 170));
+
+    dialog.ShowModal();
+}
+
+void MyFrame::OnSilent(wxCommandEvent& event)
+{
+    static bool s_silent = FALSE;
+
+    s_silent = !s_silent;
+    wxValidator::SetBellOnError(s_silent);
 
-	dialog.ShowModal();
+    event.Skip();
 }
 
-MyDialog::MyDialog( wxWindow *parent, const wxString& title, 
+MyDialog::MyDialog( wxWindow *parent, const wxString& title,
                     const wxPoint& pos, const wxSize& size, const long WXUNUSED(style) ) :
-	wxDialog(parent, VALIDATE_DIALOG_ID, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
+    wxDialog(parent, VALIDATE_DIALOG_ID, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
 {
   wxButton *but1 = new wxButton(this, wxID_OK, "OK", wxPoint(250, 10), wxSize(80, 30));
   (void)new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(250, 60), wxSize(80, 30));
diff --git a/samples/validate/validate.h b/samples/validate/validate.h
index 5b761fd321..cdb560303c 100644
--- a/samples/validate/validate.h
+++ b/samples/validate/validate.h
@@ -6,7 +6,7 @@
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:   	wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
@@ -14,34 +14,35 @@
 #endif
 
 // Define a new application type
-class MyApp: public wxApp
-{ public:
-    bool OnInit(void);
+class MyApp : public wxApp
+{
+public:
+    bool OnInit();
 };
 
 // Define a new frame type
-class MyFrame: public wxFrame
-{ public:
-    MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
-    
- public:
+class MyFrame : public wxFrame
+{
+public:
+    MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h);
+
     void OnQuit(wxCommandEvent& event);
     void OnTestDialog(wxCommandEvent& event);
+    void OnSilent(wxCommandEvent& event);
 
-   DECLARE_EVENT_TABLE()
-    
+    DECLARE_EVENT_TABLE()
 };
 
-class MyDialog: public wxDialog
+class MyDialog : public wxDialog
 {
 public:
     MyDialog(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size,
-	    const long style = wxDEFAULT_DIALOG_STYLE);
+            const long style = wxDEFAULT_DIALOG_STYLE);
 };
 
 class MyData
 {
- public:
+public:
     wxString m_string;
 
     MyData() { m_string = "My string"; }
@@ -50,5 +51,6 @@ class MyData
 #define VALIDATE_DIALOG_ID      200
 
 #define VALIDATE_TEST_DIALOG    2
+#define VALIDATE_SILENT         3
 #define VALIDATE_TEXT           101
 
diff --git a/src/common/validate.cpp b/src/common/validate.cpp
index fe0ec85316..6932875a5c 100644
--- a/src/common/validate.cpp
+++ b/src/common/validate.cpp
@@ -6,22 +6,22 @@
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:   	wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
-#pragma implementation "validate.h"
+    #pragma implementation "validate.h"
 #endif
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
 #ifndef WX_PRECOMP
-#include "wx/wx.h"
+    #include "wx/wx.h"
 #endif
 
 #include "wx/validate.h"
@@ -29,10 +29,14 @@
 const wxValidator wxDefaultValidator;
 
 #if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxValidator, wxEvtHandler)
+    IMPLEMENT_DYNAMIC_CLASS(wxValidator, wxEvtHandler)
 #endif
 
-wxValidator::wxValidator(void)
+// VZ: personally, I think TRUE would be more appropriate - these bells are
+//     _annoying_
+bool wxValidator::ms_isSilent = FALSE;
+
+wxValidator::wxValidator()
 {
   m_validatorWindow = (wxWindow *) NULL;
 }
diff --git a/src/common/valtext.cpp b/src/common/valtext.cpp
index c3139ccfb6..259b201326 100644
--- a/src/common/valtext.cpp
+++ b/src/common/valtext.cpp
@@ -6,26 +6,26 @@
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:   	wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
-#pragma implementation "valtext.h"
+    #pragma implementation "valtext.h"
 #endif
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
 #ifndef WX_PRECOMP
-#include <stdio.h>
-#include "wx/textctrl.h"
-#include "wx/utils.h"
-#include "wx/msgdlg.h"
-#include "wx/intl.h"
+    #include <stdio.h>
+    #include "wx/textctrl.h"
+    #include "wx/utils.h"
+    #include "wx/msgdlg.h"
+    #include "wx/intl.h"
 #endif
 
 #include "wx/valtext.h"
@@ -35,14 +35,14 @@
 #include <stdlib.h>
 
 #ifdef __SALFORDC__
-#include <clib.h>
+    #include <clib.h>
 #endif
 
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxTextValidator, wxValidator)
 
 BEGIN_EVENT_TABLE(wxTextValidator, wxValidator)
-	EVT_CHAR(wxTextValidator::OnChar)
+    EVT_CHAR(wxTextValidator::OnChar)
 END_EVENT_TABLE()
 #endif
 
@@ -50,13 +50,13 @@ static bool wxIsNumeric(const wxString& val);
 
 wxTextValidator::wxTextValidator(long style, wxString *val)
 {
-	m_validatorStyle = style ;
-	m_stringValue = val ;
+    m_validatorStyle = style ;
+    m_stringValue = val ;
 /*
     m_refData = new wxVTextRefData;
 
-	M_VTEXTDATA->m_validatorStyle = style ;
-	M_VTEXTDATA->m_stringValue = val ;
+    M_VTEXTDATA->m_validatorStyle = style ;
+    M_VTEXTDATA->m_stringValue = val ;
 */
 }
 
@@ -69,23 +69,23 @@ bool wxTextValidator::Copy(const wxTextValidator& val)
 {
     wxValidator::Copy(val);
 
-	m_validatorStyle = val.m_validatorStyle ;
-	m_stringValue = val.m_stringValue ;
-
-	wxNode *node = val.m_includeList.First() ;
-	while ( node )
-	{
-		char *s = (char *)node->Data();
-		m_includeList.Add(s);
-		node = node->Next();
-	}
-	node = val.m_excludeList.First() ;
-	while ( node )
-	{
-		char *s = (char *)node->Data();
-		m_excludeList.Add(s);
-		node = node->Next();
-	}
+    m_validatorStyle = val.m_validatorStyle ;
+    m_stringValue = val.m_stringValue ;
+
+    wxNode *node = val.m_includeList.First() ;
+    while ( node )
+    {
+        char *s = (char *)node->Data();
+        m_includeList.Add(s);
+        node = node->Next();
+    }
+    node = val.m_excludeList.First() ;
+    while ( node )
+    {
+        char *s = (char *)node->Data();
+        m_excludeList.Add(s);
+        node = node->Next();
+    }
     return TRUE;
 }
 
@@ -95,227 +95,214 @@ wxTextValidator::~wxTextValidator()
 
 static bool wxIsAlpha(const wxString& val)
 {
-	int i;
-	for ( i = 0; i < (int)val.Length(); i++)
-	{
-		if (!isalpha(val[i]))
-			return FALSE;
-	}
-	return TRUE;
+    int i;
+    for ( i = 0; i < (int)val.Length(); i++)
+    {
+        if (!isalpha(val[i]))
+            return FALSE;
+    }
+    return TRUE;
 }
 
 static bool wxIsAlphaNumeric(const wxString& val)
 {
-	int i;
-	for ( i = 0; i < (int)val.Length(); i++)
-	{
-		if (!isalnum(val[i]))
-			return FALSE;
-	}
-	return TRUE;
+    int i;
+    for ( i = 0; i < (int)val.Length(); i++)
+    {
+        if (!isalnum(val[i]))
+            return FALSE;
+    }
+    return TRUE;
 }
 
 // Called when the value in the window must be validated.
 // This function can pop up an error message.
 bool wxTextValidator::Validate(wxWindow *parent)
 {
-	if ( !m_validatorWindow )
-		return FALSE;
-	if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
-		return FALSE;
-	if ( !m_stringValue )
-		return FALSE;
-
-	wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
-
-	// If window is disabled, don't validate
-	if ( !control->Enabled() )
-		return FALSE;
-
-	wxString val(control->GetValue());
-
-	if ( m_validatorStyle & wxFILTER_INCLUDE_LIST )
-	{
-		if ( !m_includeList.Member(val) )
-		{
-            m_validatorWindow->SetFocus();
-			char buf[512];
-			sprintf(buf, _("%s is invalid."), (const char *)val);
-			wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
-			return FALSE;
-		}
-	}
-	if ( m_validatorStyle & wxFILTER_EXCLUDE_LIST )
-	{
-		if ( m_excludeList.Member(val) )
-		{
-            m_validatorWindow->SetFocus();
-			char buf[512];
-			sprintf(buf, _("%s is invalid."), (const char *)val);
-			wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
-			return FALSE;
-		}
-	}
-	if ( (m_validatorStyle & wxFILTER_ASCII) && !val.IsAscii() )
-	{
-            m_validatorWindow->SetFocus();
-			char buf[512];
-			sprintf(buf, _("%s should only contain ASCII characters."), (const char *)val);
-			wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
-			return FALSE;
-	}
-	if ( (m_validatorStyle & wxFILTER_ALPHA) && !wxIsAlpha(val) )
-	{
-            m_validatorWindow->SetFocus();
-			char buf[512];
-			sprintf(buf, _("%s should only contain alphabetic characters."), (const char *)val);
-			wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
-			return FALSE;
-	}
-	if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsAlphaNumeric(val))
-	{
-            m_validatorWindow->SetFocus();
-			char buf[512];
-			sprintf(buf, _("%s should only contain alphabetic or numeric characters."), (const char *)val);
-			wxMessageBox(buf,_("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
-			return FALSE;
-	}
-	if ( (m_validatorStyle & wxFILTER_NUMERIC) && !wxIsNumeric(val))
-
-	{
-            m_validatorWindow->SetFocus();
-			char buf[512];
-			sprintf(buf, _("%s should be numeric."), (const char *)val);
-			wxMessageBox(buf, _("Validation conflict"), wxOK | wxICON_EXCLAMATION, parent);
-			return FALSE;
-	}
-
-	return TRUE ;
+    if ( !m_validatorWindow )
+        return FALSE;
+    if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
+        return FALSE;
+    if ( !m_stringValue )
+        return FALSE;
+
+    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
+
+    // If window is disabled, don't validate
+    if ( !control->Enabled() )
+        return FALSE;
+
+    wxString val(control->GetValue());
+
+    bool ok = true;
+
+    // this format string should contian exactly one '%s'
+    const char *errormsg = _("'%s' is invalid");
+
+    if ( m_validatorStyle & wxFILTER_INCLUDE_LIST )
+    {
+        if ( !m_includeList.Member(val) )
+        {
+            ok = false;
+        }
+    }
+    else if ( m_validatorStyle & wxFILTER_EXCLUDE_LIST )
+    {
+        if ( m_excludeList.Member(val) )
+        {
+            ok = false;
+        }
+    }
+    else if ( (m_validatorStyle & wxFILTER_ASCII) && !val.IsAscii() )
+    {
+        ok = false;
+
+        errormsg = _("'%s' should only contain ASCII characters.");
+    }
+    else if ( (m_validatorStyle & wxFILTER_ALPHA) && !wxIsAlpha(val) )
+    {
+        ok = false;
+
+        errormsg = _("'%s' should only contain alphabetic characters.");
+    }
+    else if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsAlphaNumeric(val))
+    {
+        ok = false;
+
+        errormsg = _("'%s' should only contain alphabetic or numeric characters.");
+    }
+    else if ( (m_validatorStyle & wxFILTER_NUMERIC) && !wxIsNumeric(val))
+    {
+        ok = false;
+
+        errormsg = _("'%s' should be numeric.");
+    }
+
+    if ( !ok )
+    {
+        m_validatorWindow->SetFocus();
+
+        wxString buf;
+        buf.Printf(errormsg, val.c_str());
+
+        wxMessageBox(buf, _("Validation conflict"),
+                     wxOK | wxICON_EXCLAMATION, parent);
+    }
+
+    return ok;
 }
 
 // Called to transfer data to the window
 bool wxTextValidator::TransferToWindow(void)
 {
-	if ( !m_validatorWindow )
-		return FALSE;
-	if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
-		return FALSE;
-	if ( !m_stringValue )
-		return FALSE;
+    if ( !m_validatorWindow )
+        return FALSE;
+    if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
+        return FALSE;
+    if ( !m_stringValue )
+        return FALSE;
 
-	wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
-	control->SetValue(* m_stringValue) ;
+    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
+    control->SetValue(* m_stringValue) ;
 
-	return TRUE;
+    return TRUE;
 }
 
 // Called to transfer data to the window
 bool wxTextValidator::TransferFromWindow(void)
 {
-	if ( !m_validatorWindow )
-		return FALSE;
-	if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
-		return FALSE;
-	if ( !m_stringValue )
-		return FALSE;
+    if ( !m_validatorWindow )
+        return FALSE;
+    if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
+        return FALSE;
+    if ( !m_stringValue )
+        return FALSE;
 
-	wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
-	* m_stringValue = control->GetValue() ;
+    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
+    * m_stringValue = control->GetValue() ;
 
-	return TRUE;
+    return TRUE;
 }
 
 void wxTextValidator::SetIncludeList(const wxStringList& list)
 {
 /*
-	if ( !M_VTEXTDATA )
-		return;
+    if ( !M_VTEXTDATA )
+        return;
 */
 
-	m_includeList.Clear();
-	// TODO: replace with =
-	wxNode *node = list.First() ;
-	while ( node )
-	{
-		char *s = (char *)node->Data();
-		m_includeList.Add(s);
-		node = node->Next();
-	}
+    m_includeList.Clear();
+    // TODO: replace with =
+    wxNode *node = list.First() ;
+    while ( node )
+    {
+        char *s = (char *)node->Data();
+        m_includeList.Add(s);
+        node = node->Next();
+    }
 }
 
 void wxTextValidator::SetExcludeList(const wxStringList& list)
 {
 /*
-	if ( !M_VTEXTDATA )
-		return;
+    if ( !M_VTEXTDATA )
+        return;
 */
 
-	m_excludeList.Clear();
-	// TODO: replace with =
-	wxNode *node = list.First() ;
-	while ( node )
-	{
-		char *s = (char *)node->Data();
-		m_excludeList.Add(s);
-		node = node->Next();
-	}
+    m_excludeList.Clear();
+    // TODO: replace with =
+    wxNode *node = list.First() ;
+    while ( node )
+    {
+        char *s = (char *)node->Data();
+        m_excludeList.Add(s);
+        node = node->Next();
+    }
 }
 
 void wxTextValidator::OnChar(wxKeyEvent& event)
 {
 /*
-	if ( !M_VTEXTDATA )
-		return;
+    if ( !M_VTEXTDATA )
+        return;
 */
 
-	if ( !m_validatorWindow )
-		return;
-
-	wxTextCtrl *textCtrl = (wxTextCtrl *)m_validatorWindow;
-
-	int keyCode = event.KeyCode();
-	if (keyCode == WXK_DELETE || keyCode == WXK_RETURN || keyCode == WXK_BACK ||
-	    keyCode == WXK_HOME || keyCode == WXK_LEFT || keyCode == WXK_UP ||
-	    keyCode == WXK_RIGHT || keyCode == WXK_DOWN || keyCode == WXK_PRIOR ||
-	    keyCode == WXK_NEXT || keyCode == WXK_END || keyCode == WXK_HOME)
-	{
-		textCtrl->wxTextCtrl::OnChar(event);
-		return ;
-	}
-
-	if ( (m_validatorStyle & wxFILTER_ASCII) && !isascii(keyCode) )
-	{
-		wxBell();
-		return;
-	}
-	if ( (m_validatorStyle & wxFILTER_ALPHA) && !isalpha(keyCode) )
-	{
-		wxBell();
-		return;
-	}
-	if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !isalnum(keyCode) )
-	{
-		wxBell();
-		return;
-	}
-	if ( (m_validatorStyle & wxFILTER_NUMERIC) && !isdigit(keyCode) && keyCode != '.' && keyCode != '-')
-	{
-		wxBell();
-		return;
-	}
-
-	textCtrl->wxTextCtrl::OnChar(event);
+    if ( m_validatorWindow )
+    {
+        int keyCode = event.KeyCode();
+
+        // we don't filter special keys and Delete
+        if (
+             !(keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode > WXK_START) &&
+             (
+              ((m_validatorStyle & wxFILTER_ASCII) && !isascii(keyCode)) ||
+              ((m_validatorStyle & wxFILTER_ALPHA) && !isalpha(keyCode)) ||
+              ((m_validatorStyle & wxFILTER_ALPHANUMERIC) && !isalnum(keyCode)) ||
+              ((m_validatorStyle & wxFILTER_NUMERIC) && !isdigit(keyCode)
+                                && keyCode != '.' && keyCode != '-')
+             )
+           )
+        {
+            if ( !wxValidator::IsSilent() )
+                wxBell();
+
+            // eat message
+            return;
+        }
+    }
+
+    event.Skip();
 }
 
 static bool wxIsNumeric(const wxString& val)
 {
-	int i;
-	for ( i = 0; i < (int)val.Length(); i++)
-	{
-		if ((!isdigit(val[i])) && (val[i] != '.'))
-		  if(!((i == 0) && (val[i] == '-')))
-			return FALSE;
-	}
-	return TRUE;
+    int i;
+    for ( i = 0; i < (int)val.Length(); i++)
+    {
+        if ((!isdigit(val[i])) && (val[i] != '.'))
+          if(!((i == 0) && (val[i] == '-')))
+            return FALSE;
+    }
+    return TRUE;
 }
 
-- 
2.50.0

