Пример #1
0
// Called when the value in the window must be validated.
// This function can pop up an error message.
bool wxNumericTextValidator::Validate(wxWindow *parent)
{
    if (!CheckValidator())
        return false;

    wxTextCtrl* control = dynamic_cast<wxTextCtrl*>(m_validatorWindow);

    if (!control)
        return false;

    // If window is disabled, simply return
    if ( !control->IsEnabled() )
        return true;

    if (!wxIsNumeric(control->GetValue()))
    {
        m_validatorWindow->SetFocus();

        wxString buf;
        buf.Printf(_("'%s' should be numeric."), control->GetValue().c_str());

        wxMessageBox(buf, _("Validation conflict"),
                     wxOK | wxICON_EXCLAMATION, parent);

        return false;
    }

    return true;
}
Пример #2
0
bool CValidateEmailAddress::TransferToWindow(void) {
    if(!CheckValidator())
        return FALSE;
    
    if (!m_stringValue)
        return TRUE;

    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
    control->SetValue(* m_stringValue) ;

    return TRUE;
}
Пример #3
0
bool wxRegExValidator::TransferFromWindow(void)
{
	if( !CheckValidator() )
		return false;

	if ( m_stringValue )
	{
		wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow;
		*m_stringValue = control->GetValue();
	}

	return true;
}
Пример #4
0
bool wxRegExValidator::TransferToWindow()
{
	if( !CheckValidator() )
		return false;

	if ( m_stringValue )
	{
		wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow;
		control->SetValue(* m_stringValue);
	}

	return true;
}
Пример #5
0
bool wxSimpleListValidator::TransferFromWindow(void) {
    if ( !CheckValidator() )
        return false;

    int sel = wxNOT_FOUND;

    if (dynamic_cast<wxControlWithItems*>(m_validatorWindow)) {
        if ((m_kind == Val_String) && m_pString) {
            *m_pString = dynamic_cast<wxControlWithItems*>(m_validatorWindow)->GetStringSelection();
        }
        sel = dynamic_cast<wxControlWithItems*>(m_validatorWindow)->GetSelection();
    } else if (dynamic_cast<wxVListBox*>(m_validatorWindow)) {
        sel = dynamic_cast<wxVListBox*>(m_validatorWindow)->GetSelection();
    }

    if (sel == wxNOT_FOUND) {
        return false;
    }
    if (m_pChar) {
        switch (m_kind) {
        case Val_Char:
            *m_pChar = sel;
            break;
        case Val_Int:
            *m_pInt = sel;
            break;
        case Val_Long:
            *m_pLong = sel;
            break;
        case Val_UChar:
            *m_pUChar = sel;
            break;
        case Val_UInt:
            *m_pUInt = sel;
            break;
        case Val_ULong:
            *m_pULong = sel;
            break;
        case Val_String:
            break;
        default:
            return false;
        }
    } else {
        return false;
    }

    return true;
}
Пример #6
0
bool wxSimpleListValidator::TransferToWindow(void) {
    if ( !CheckValidator() )
        return false;

    if (!m_pChar)
        return false;

    int sel = wxNOT_FOUND;

    if (m_pChar) {
        switch (m_kind) {
        case Val_Char:
            sel = *m_pChar;
            break;
        case Val_Int:
            sel = *m_pInt;
            break;
        case Val_Long:
            sel = *m_pLong;
            break;
        case Val_UChar:
            sel = *m_pUChar;
            break;
        case Val_UInt:
            sel = *m_pUInt;
            break;
        case Val_ULong:
            sel = *m_pULong;
            break;
        default:
            sel = wxNOT_FOUND;
        }
    }

    if (dynamic_cast<wxControlWithItems*>(m_validatorWindow)) {
        if ((m_kind == Val_String) && m_pString) {
            sel = dynamic_cast<wxControlWithItems*>(m_validatorWindow)->FindString(*m_pString);
        }
        dynamic_cast<wxControlWithItems*>(m_validatorWindow)->SetSelection(sel);
    } else if (dynamic_cast<wxVListBox*>(m_validatorWindow)) {
        dynamic_cast<wxVListBox*>(m_validatorWindow)->SetSelection(sel);
    } else {
        return false;
    }

    return true;
}
Пример #7
0
bool wxSimpleListValidator::Validate(wxWindow* parent) {
    if ( !CheckValidator() )
        return false;

    bool valid = false;
    if (dynamic_cast<wxControlWithItems*>(m_validatorWindow)) {
        valid = (dynamic_cast<wxControlWithItems*>(m_validatorWindow)->GetSelection()!=wxNOT_FOUND);
    } else if (dynamic_cast<wxVListBox*>(m_validatorWindow)) {
        valid = (dynamic_cast<wxVListBox*>(m_validatorWindow)->GetSelection()!=wxNOT_FOUND);
    }

    if ((!valid) && (!m_silent)) {
        m_validatorWindow->SetFocus();
        ::wxMessageBox(_("You need to select something in this list."), _("Validation conflict"), wxOK|wxICON_ERROR, parent);
    }

    return valid;
}
Пример #8
0
bool wxRegExValidator::Validate(wxWindow *parent)
{
	if( !CheckValidator() )
		return false;

	wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow;

	// If window is disabled, simply return
	if ( !control->IsEnabled() )
		return true;

	if(!m_regEx.IsValid())
	{
		wxMessageBox(wxT("The regular expression provided has a syntax error."), wxT("Invalid expression"),
			wxOK | wxICON_ERROR, parent);
		return false;
	}

	wxString val(control->GetValue());

	bool bMatch = false;
	if ( m_regEx.Matches(val) )
	{
		if ( m_regEx.GetMatch(val) == val )
		{
			bMatch = true;
		}
	}

	if (!bMatch) 
	{
		wxASSERT_MSG( !m_strErrorMsg.empty(), wxT("you forgot to set errormsg") );

		m_validatorWindow->SetFocus();

		wxString buf = wxString::Format(wxT("'%s'%s"), val.c_str(), m_strErrorMsg);

		wxMessageBox(buf, wxT("Validation conflict"),
			wxOK | wxICON_EXCLAMATION, parent);
	}

	return bMatch;
}
Пример #9
0
// Called to transfer data from the window
bool wxNumericTextValidator::TransferFromWindow()
{
    if (!CheckValidator())
        return false;

    if (!_longValue
     && !_UlongValue)
        return true;

    wxTextCtrl* control = dynamic_cast<wxTextCtrl*>(m_validatorWindow);

    if (!control)
        return false;

    if (_longValue)
        control->GetValue().ToLong(_longValue);
    else
        control->GetValue().ToULong(_UlongValue);

    return true;
}
Пример #10
0
// Called to transfer data to the window
bool wxNumericTextValidator::TransferToWindow()
{
    if (!CheckValidator())
        return false;

    if (!_longValue
     && !_UlongValue)
        return true;

    wxTextCtrl* control = dynamic_cast<wxTextCtrl*>(m_validatorWindow);

    if (!control)
        return false;

    if (_longValue)
        control->SetValue(wxString::Format(_T("%d"), *_longValue));
    else
        control->SetValue(wxString::Format(_T("%u"), *_UlongValue));

    return true;
}
Пример #11
0
bool CValidateEmailAddress::Validate(wxWindow *parent) {
    if(!CheckValidator())
        return FALSE;

    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;

    if (!control->IsEnabled())
        return TRUE;

    bool ok = TRUE;
    wxString val(control->GetValue().Trim().Trim(false));  // trim spaces before and after

    // Regular Expression from Frank S. Thomas
    wxRegEx reEmail(
        wxT("^([^@]+)@([^@\\.]+)\\.([^@]{2,})$"));

    if (val.Length() == 0) {
        ok = FALSE;
        m_errormsg = _("Please specify an email address");
    } else if (!reEmail.Matches(val)) {
        ok = FALSE;
        m_errormsg = _("Invalid email address; please enter a valid email address");
    }

    if (!ok) {
        wxASSERT_MSG(!m_errormsg.empty(), _T("you forgot to set errormsg"));

        m_validatorWindow->SetFocus();

        wxString buf;
        buf.Printf(m_errormsg, control->GetValue().c_str());

        wxGetApp().SafeMessageBox(buf, _("Validation conflict"),
            wxOK | wxICON_EXCLAMATION, parent
        );
    }

    return ok;
}
Пример #12
0
        // Called to transfer data to the window
        virtual bool TransferToWindow()
        {
            if (!CheckValidator())
                return false;

            wxListCtrl* control = dynamic_cast<wxListCtrl*>(m_validatorWindow);

            if (!control)
                return false;

            size_t count = control->GetItemCount();

            // clear all selections
            for (size_t i = 0; i < count; ++i)
                control->SetItemState(i, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);

            // select each item in our array
            for (typename Container::const_iterator i = _SelectionContainer->begin(); i != _SelectionContainer->end(); ++i)
                control->SetItemState(*i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);

            return true;
        }
Пример #13
0
        // Called to transfer data to the window
        virtual bool TransferFromWindow()
        {
            if (!CheckValidator())
                return false;

            wxListCtrl* control = dynamic_cast<wxListCtrl*>(m_validatorWindow);

            if (!control)
                return false;

            // clear our array
            _SelectionContainer->clear();

            // add each selected item to our array
            const size_t count = control->GetItemCount();
            for (size_t i = 0; i < count; ++i)
            {
                if (control->GetItemState(i, wxLIST_STATE_SELECTED))
                    _SelectionContainer->push_back(i);
            }

            return true;
        }
Пример #14
0
 // Called when the value in the window must be validated.
 // This function can pop up an error message.
 virtual bool Validate(wxWindow* parent)
 {
     return CheckValidator();
 }
Пример #15
0
// Called when the value in the window must be validated.
// This function can pop up an error message.
bool wxTextValidator::Validate(wxWindow *parent)
{
    if( !CheckValidator() )
        return false;

    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow;

    // If window is disabled, simply return
    if ( !control->IsEnabled() )
        return true;

    wxString val(control->GetValue());

    bool ok = true;

    // NB: this format string should contian exactly one '%s'
    wxString errormsg;

    bool includes = (m_validatorStyle & wxFILTER_INCLUDE_LIST) != 0;
    if ( includes || (m_validatorStyle & wxFILTER_EXCLUDE_LIST) )
    {
        // if includes, it's only ok to have the members of the list,
        // otherwise it's only ok to have non-members
        ok = includes == (m_includes.Index(val) != wxNOT_FOUND);
        if ( !ok )
        {
            errormsg = _("'%s' is invalid");
        }
    }
    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.");
    }
    else if ( (m_validatorStyle & wxFILTER_INCLUDE_CHAR_LIST) && !IsInCharIncludes(val))
    {
        //it's only ok to have the members of the list
        errormsg = _("'%s' is invalid");
        ok = false;
    }
    else if ( (m_validatorStyle & wxFILTER_EXCLUDE_CHAR_LIST) && !IsNotInCharExcludes(val))
    {
        // it's only ok to have non-members of the list
        errormsg = _("'%s' is invalid");
        ok = false;
    }

    if ( !ok )
    {
        wxASSERT_MSG( !errormsg.empty(), _T("you forgot to set errormsg") );

        m_validatorWindow->SetFocus();

        wxString buf;
        buf.Printf(errormsg, val.c_str());

        wxMessageBox(buf, _("Validation conflict"),
                     wxOK | wxICON_EXCLAMATION, parent);
    }

    return ok;
}