Listing 4: pwd_box.cpp — Implementation of the custom dialog box class

#include "pwd_box.h"

BEGIN_EVENT_TABLE (PasswordDlg, wxDialog)
    EVT_TEXT (ID_name, PasswordDlg::OnTextChanged)
    EVT_TEXT (ID_pwd,  PasswordDlg::OnTextChanged)
END_EVENT_TABLE ()


PasswordDlg::PasswordDlg (wxWindow * parent,
                          const wxString & title,
                          const wxPoint & position)
    : wxDialog (parent, -1, title, position, wxSize (220,115))
{
    m_label_name = new wxStaticText (this, ID_label_name, "Name:", wxPoint(20,20), wxDefaultSize);
    m_label_password = new wxStaticText (this, ID_label_pwd, "Password:", wxPoint (20,45));
    m_name = new wxTextCtrl (this, ID_name, "", wxPoint (100,20), wxSize(100,20));
    m_password = new wxTextCtrl (this, ID_pwd, "", wxPoint(100,45), wxSize(100,20), wxTE_PASSWORD);
    m_ok = new wxButton (this, wxID_OK, "OK", wxPoint(50,80), wxSize(50,20));
    m_cancel = new wxButton (this, wxID_CANCEL, "Cancel", wxPoint (120,80), wxSize(50,20));

    m_ok->Enable (false);
}


void PasswordDlg::OnTextChanged (wxCommandEvent &)
{
    if (m_name->GetValue() != "" && m_password->GetValue() != "")
    {
        m_ok->Enable (true);
    }
    else
    {
        m_ok->Enable (false);
    }
}
— End of Listing —