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
This commit is contained in:
Vadim Zeitlin
1999-02-25 14:47:18 +00:00
parent bb0ca8dfcc
commit a994f81b94
8 changed files with 302 additions and 271 deletions

View File

@@ -64,6 +64,13 @@ This base function returns NULL.
Returns the window associated with the validator. 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} \membersection{wxValidator::SetWindow}\label{wxvalidatorsetwindow}
\func{void}{SetWindow}{\param{wxWindow*}{ window}} \func{void}{SetWindow}{\param{wxWindow*}{ window}}

View File

@@ -68,6 +68,8 @@ public:
void Append( const wxString &item, void* clientData ); void Append( const wxString &item, void* clientData );
void Append( const wxString &item, wxClientData* clientData ); void Append( const wxString &item, wxClientData* clientData );
void InsertItems(int nItems, const wxString items[], int pos);
void SetClientData( int n, void* clientData ); void SetClientData( int n, void* clientData );
void* GetClientData( int n ); void* GetClientData( int n );
void SetClientObject( int n, wxClientData* clientData ); void SetClientObject( int n, wxClientData* clientData );

View File

@@ -68,6 +68,8 @@ public:
void Append( const wxString &item, void* clientData ); void Append( const wxString &item, void* clientData );
void Append( const wxString &item, wxClientData* clientData ); void Append( const wxString &item, wxClientData* clientData );
void InsertItems(int nItems, const wxString items[], int pos);
void SetClientData( int n, void* clientData ); void SetClientData( int n, void* clientData );
void* GetClientData( int n ); void* GetClientData( int n );
void SetClientObject( int n, wxClientData* clientData ); void SetClientObject( int n, wxClientData* clientData );

View File

@@ -6,14 +6,14 @@
// Created: 29/01/98 // Created: 29/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1998 Julian Smart // Copyright: (c) 1998 Julian Smart
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_VALIDATEH__ #ifndef _WX_VALIDATEH__
#define _WX_VALIDATEH__ #define _WX_VALIDATEH__
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "validate.h" #pragma interface "validate.h"
#endif #endif
#include "wx/event.h" #include "wx/event.h"
@@ -30,38 +30,49 @@ class WXDLLEXPORT wxWindow;
to intercept e.g. OnChar. to intercept e.g. OnChar.
Note that wxValidator and derived classes use reference counting. Note that wxValidator and derived classes use reference counting.
*/ */
class WXDLLEXPORT wxValidator: public wxEvtHandler class WXDLLEXPORT wxValidator : public wxEvtHandler
{ {
DECLARE_DYNAMIC_CLASS(wxValidator)
public: public:
wxValidator(void); wxValidator();
~wxValidator(); ~wxValidator();
// Make a clone of this validator (or return NULL) - currently necessary // Make a clone of this validator (or return NULL) - currently necessary
// if you're passing a reference to a validator. // if you're passing a reference to a validator.
// Another possibility is to always pass a pointer to a new 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). // (so the calling code can use a copy constructor of the relevant class).
virtual wxValidator *Clone(void) const { return (wxValidator *) NULL; } virtual wxValidator *Clone() const
inline bool Copy(const wxValidator& val) { m_validatorWindow = val.m_validatorWindow; return TRUE; } { 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. // Called when the value in the window must be validated.
// This function can pop up an error message. // This function can pop up an error message.
virtual bool Validate(wxWindow *WXUNUSED(parent)) { return FALSE; }; virtual bool Validate(wxWindow *WXUNUSED(parent)) { return FALSE; };
// Called to transfer data to the window // Called to transfer data to the window
virtual bool TransferToWindow(void) { return FALSE; } virtual bool TransferToWindow() { return FALSE; }
// Called to transfer data from the window // Called to transfer data from the window
virtual bool TransferFromWindow(void) { return FALSE; }; virtual bool TransferFromWindow() { return FALSE; };
// ACCESSORS // accessors
inline wxWindow *GetWindow(void) const { return m_validatorWindow; } wxWindow *GetWindow() const { return m_validatorWindow; }
inline void SetWindow(wxWindow *win) { m_validatorWindow = win; } 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: protected:
wxWindow *m_validatorWindow; wxWindow *m_validatorWindow;
private:
static bool ms_isSilent;
DECLARE_DYNAMIC_CLASS(wxValidator)
}; };
WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator; WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator;

View File

@@ -6,7 +6,7 @@
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem // Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -30,66 +30,82 @@
#include "validate.h" #include "validate.h"
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog) EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog)
EVT_MENU(VALIDATE_SILENT, MyFrame::OnSilent)
END_EVENT_TABLE() END_EVENT_TABLE()
IMPLEMENT_APP(MyApp) IMPLEMENT_APP(MyApp)
MyData g_data; MyData g_data;
bool MyApp::OnInit(void) bool MyApp::OnInit()
{ {
// Create the main frame window // 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);
// Give it an icon
#ifdef __WXMSW__
frame->SetIcon(wxIcon("mondrian"));
#endif
#ifdef __X__
frame->SetIcon(wxIcon("aiai.xbm"));
#endif
// Make a menubar
wxMenu *file_menu = new wxMenu;
file_menu->Append(VALIDATE_TEST_DIALOG, "&Test dialog");
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 // Show the frame
frame->Show(TRUE); frame->Show(TRUE);
SetTopWindow(frame); SetTopWindow(frame);
return TRUE; return TRUE;
} }
// My frame constructor // My frame constructor
MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): 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)) : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
{} {
// Give it an icon
#ifdef __WXMSW__
SetIcon(wxIcon("mondrian"));
#endif
#ifdef __X__
SetIcon(wxIcon("aiai.xbm"));
#endif
// Make a menubar
wxMenu *file_menu = new wxMenu;
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");
file_menu->Check(VALIDATE_SILENT, wxValidator::IsSilent());
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "File");
SetMenuBar(menu_bar);
CreateStatusBar(1);
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{ {
Close(TRUE); Close(TRUE);
} }
void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event)) 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(); dialog.ShowModal();
} }
MyDialog::MyDialog( wxWindow *parent, const wxString& title, void MyFrame::OnSilent(wxCommandEvent& event)
{
static bool s_silent = FALSE;
s_silent = !s_silent;
wxValidator::SetBellOnError(s_silent);
event.Skip();
}
MyDialog::MyDialog( wxWindow *parent, const wxString& title,
const wxPoint& pos, const wxSize& size, const long WXUNUSED(style) ) : 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)); 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)); (void)new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(250, 60), wxSize(80, 30));

View File

@@ -6,7 +6,7 @@
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem // Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -14,34 +14,35 @@
#endif #endif
// Define a new application type // Define a new application type
class MyApp: public wxApp class MyApp : public wxApp
{ public: {
bool OnInit(void); public:
bool OnInit();
}; };
// Define a new frame type // Define a new frame type
class MyFrame: public wxFrame class MyFrame : public wxFrame
{ public: {
MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); public:
MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h);
public:
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnTestDialog(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: public:
MyDialog(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, 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 class MyData
{ {
public: public:
wxString m_string; wxString m_string;
MyData() { m_string = "My string"; } MyData() { m_string = "My string"; }
@@ -50,5 +51,6 @@ class MyData
#define VALIDATE_DIALOG_ID 200 #define VALIDATE_DIALOG_ID 200
#define VALIDATE_TEST_DIALOG 2 #define VALIDATE_TEST_DIALOG 2
#define VALIDATE_SILENT 3
#define VALIDATE_TEXT 101 #define VALIDATE_TEXT 101

View File

@@ -6,22 +6,22 @@
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem // Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "validate.h" #pragma implementation "validate.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/wx.h" #include "wx/wx.h"
#endif #endif
#include "wx/validate.h" #include "wx/validate.h"
@@ -29,10 +29,14 @@
const wxValidator wxDefaultValidator; const wxValidator wxDefaultValidator;
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxValidator, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxValidator, wxEvtHandler)
#endif #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; m_validatorWindow = (wxWindow *) NULL;
} }

View File

@@ -6,26 +6,26 @@
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem // Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "valtext.h" #pragma implementation "valtext.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include <stdio.h> #include <stdio.h>
#include "wx/textctrl.h" #include "wx/textctrl.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#include "wx/intl.h" #include "wx/intl.h"
#endif #endif
#include "wx/valtext.h" #include "wx/valtext.h"
@@ -35,14 +35,14 @@
#include <stdlib.h> #include <stdlib.h>
#ifdef __SALFORDC__ #ifdef __SALFORDC__
#include <clib.h> #include <clib.h>
#endif #endif
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxTextValidator, wxValidator) IMPLEMENT_DYNAMIC_CLASS(wxTextValidator, wxValidator)
BEGIN_EVENT_TABLE(wxTextValidator, wxValidator) BEGIN_EVENT_TABLE(wxTextValidator, wxValidator)
EVT_CHAR(wxTextValidator::OnChar) EVT_CHAR(wxTextValidator::OnChar)
END_EVENT_TABLE() END_EVENT_TABLE()
#endif #endif
@@ -50,13 +50,13 @@ static bool wxIsNumeric(const wxString& val);
wxTextValidator::wxTextValidator(long style, wxString *val) wxTextValidator::wxTextValidator(long style, wxString *val)
{ {
m_validatorStyle = style ; m_validatorStyle = style ;
m_stringValue = val ; m_stringValue = val ;
/* /*
m_refData = new wxVTextRefData; m_refData = new wxVTextRefData;
M_VTEXTDATA->m_validatorStyle = style ; M_VTEXTDATA->m_validatorStyle = style ;
M_VTEXTDATA->m_stringValue = val ; M_VTEXTDATA->m_stringValue = val ;
*/ */
} }
@@ -69,23 +69,23 @@ bool wxTextValidator::Copy(const wxTextValidator& val)
{ {
wxValidator::Copy(val); wxValidator::Copy(val);
m_validatorStyle = val.m_validatorStyle ; m_validatorStyle = val.m_validatorStyle ;
m_stringValue = val.m_stringValue ; m_stringValue = val.m_stringValue ;
wxNode *node = val.m_includeList.First() ; wxNode *node = val.m_includeList.First() ;
while ( node ) while ( node )
{ {
char *s = (char *)node->Data(); char *s = (char *)node->Data();
m_includeList.Add(s); m_includeList.Add(s);
node = node->Next(); node = node->Next();
} }
node = val.m_excludeList.First() ; node = val.m_excludeList.First() ;
while ( node ) while ( node )
{ {
char *s = (char *)node->Data(); char *s = (char *)node->Data();
m_excludeList.Add(s); m_excludeList.Add(s);
node = node->Next(); node = node->Next();
} }
return TRUE; return TRUE;
} }
@@ -95,227 +95,214 @@ wxTextValidator::~wxTextValidator()
static bool wxIsAlpha(const wxString& val) static bool wxIsAlpha(const wxString& val)
{ {
int i; int i;
for ( i = 0; i < (int)val.Length(); i++) for ( i = 0; i < (int)val.Length(); i++)
{ {
if (!isalpha(val[i])) if (!isalpha(val[i]))
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static bool wxIsAlphaNumeric(const wxString& val) static bool wxIsAlphaNumeric(const wxString& val)
{ {
int i; int i;
for ( i = 0; i < (int)val.Length(); i++) for ( i = 0; i < (int)val.Length(); i++)
{ {
if (!isalnum(val[i])) if (!isalnum(val[i]))
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
// Called when the value in the window must be validated. // Called when the value in the window must be validated.
// This function can pop up an error message. // This function can pop up an error message.
bool wxTextValidator::Validate(wxWindow *parent) bool wxTextValidator::Validate(wxWindow *parent)
{ {
if ( !m_validatorWindow ) if ( !m_validatorWindow )
return FALSE; return FALSE;
if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
return FALSE; return FALSE;
if ( !m_stringValue ) if ( !m_stringValue )
return FALSE; return FALSE;
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ; wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
// If window is disabled, don't validate // If window is disabled, don't validate
if ( !control->Enabled() ) if ( !control->Enabled() )
return FALSE; return FALSE;
wxString val(control->GetValue()); wxString val(control->GetValue());
if ( m_validatorStyle & wxFILTER_INCLUDE_LIST ) bool ok = true;
{
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))
{ // this format string should contian exactly one '%s'
m_validatorWindow->SetFocus(); const char *errormsg = _("'%s' is invalid");
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_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 // Called to transfer data to the window
bool wxTextValidator::TransferToWindow(void) bool wxTextValidator::TransferToWindow(void)
{ {
if ( !m_validatorWindow ) if ( !m_validatorWindow )
return FALSE; return FALSE;
if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
return FALSE; return FALSE;
if ( !m_stringValue ) if ( !m_stringValue )
return FALSE; return FALSE;
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ; wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
control->SetValue(* m_stringValue) ; control->SetValue(* m_stringValue) ;
return TRUE; return TRUE;
} }
// Called to transfer data to the window // Called to transfer data to the window
bool wxTextValidator::TransferFromWindow(void) bool wxTextValidator::TransferFromWindow(void)
{ {
if ( !m_validatorWindow ) if ( !m_validatorWindow )
return FALSE; return FALSE;
if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
return FALSE; return FALSE;
if ( !m_stringValue ) if ( !m_stringValue )
return FALSE; return FALSE;
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ; wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
* m_stringValue = control->GetValue() ; * m_stringValue = control->GetValue() ;
return TRUE; return TRUE;
} }
void wxTextValidator::SetIncludeList(const wxStringList& list) void wxTextValidator::SetIncludeList(const wxStringList& list)
{ {
/* /*
if ( !M_VTEXTDATA ) if ( !M_VTEXTDATA )
return; return;
*/ */
m_includeList.Clear(); m_includeList.Clear();
// TODO: replace with = // TODO: replace with =
wxNode *node = list.First() ; wxNode *node = list.First() ;
while ( node ) while ( node )
{ {
char *s = (char *)node->Data(); char *s = (char *)node->Data();
m_includeList.Add(s); m_includeList.Add(s);
node = node->Next(); node = node->Next();
} }
} }
void wxTextValidator::SetExcludeList(const wxStringList& list) void wxTextValidator::SetExcludeList(const wxStringList& list)
{ {
/* /*
if ( !M_VTEXTDATA ) if ( !M_VTEXTDATA )
return; return;
*/ */
m_excludeList.Clear(); m_excludeList.Clear();
// TODO: replace with = // TODO: replace with =
wxNode *node = list.First() ; wxNode *node = list.First() ;
while ( node ) while ( node )
{ {
char *s = (char *)node->Data(); char *s = (char *)node->Data();
m_excludeList.Add(s); m_excludeList.Add(s);
node = node->Next(); node = node->Next();
} }
} }
void wxTextValidator::OnChar(wxKeyEvent& event) void wxTextValidator::OnChar(wxKeyEvent& event)
{ {
/* /*
if ( !M_VTEXTDATA ) if ( !M_VTEXTDATA )
return; return;
*/ */
if ( !m_validatorWindow ) if ( m_validatorWindow )
return; {
int keyCode = event.KeyCode();
wxTextCtrl *textCtrl = (wxTextCtrl *)m_validatorWindow; // 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();
int keyCode = event.KeyCode(); // eat message
if (keyCode == WXK_DELETE || keyCode == WXK_RETURN || keyCode == WXK_BACK || return;
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) ) event.Skip();
{
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);
} }
static bool wxIsNumeric(const wxString& val) static bool wxIsNumeric(const wxString& val)
{ {
int i; int i;
for ( i = 0; i < (int)val.Length(); i++) for ( i = 0; i < (int)val.Length(); i++)
{ {
if ((!isdigit(val[i])) && (val[i] != '.')) if ((!isdigit(val[i])) && (val[i] != '.'))
if(!((i == 0) && (val[i] == '-'))) if(!((i == 0) && (val[i] == '-')))
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }