added wxGetPasswordFromUser(), dialogs sample shows it, documented it

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5639 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-01-24 18:26:54 +00:00
parent 88e243b29f
commit a294c6d53e
7 changed files with 92 additions and 39 deletions

View File

@@ -48,6 +48,8 @@ all (GUI):
- TIFF support added (libtiff required and included in the distribution) - TIFF support added (libtiff required and included in the distribution)
- PCX files can now be written (24 bit only so far) - PCX files can now be written (24 bit only so far)
- wxTextEntryDialog may be used for entering passwords (supports wxTE_PASSWORD)
wxMSW: wxMSW:
- support for enhanced metafiles added, support for copying/pasting metafiles - support for enhanced metafiles added, support for copying/pasting metafiles

View File

@@ -609,6 +609,19 @@ Dialog is centered on its {\it parent} unless an explicit position is given in
<wx/textdlg.h> <wx/textdlg.h>
\membersection{::wxGetPasswordFromUser}\label{wxgetpasswordfromuser}
\func{wxString}{wxGetTextFromUser}{\param{const wxString\& }{message}, \param{const wxString\& }{caption = ``Input text"},\\
\param{const wxString\& }{default\_value = ``"}, \param{wxWindow *}{parent = NULL}}
Similar to \helpref{wxGetTextFromUser}{wxgettextfromuser} but the text entered
in the dialog is not shown on screen but replaced with stars. This is intended
to be used for entering passwords as the function name implies.
\wxheading{Include files}
<wx/textdlg.h>
\membersection{::wxGetTextFromUser}\label{wxgettextfromuser} \membersection{::wxGetTextFromUser}\label{wxgettextfromuser}
\func{wxString}{wxGetTextFromUser}{\param{const wxString\& }{message}, \param{const wxString\& }{caption = ``Input text"},\\ \func{wxString}{wxGetTextFromUser}{\param{const wxString\& }{message}, \param{const wxString\& }{caption = ``Input text"},\\

View File

@@ -35,7 +35,9 @@ Constructor. Use \helpref{wxTextEntryDialog::ShowModal}{wxtextentrydialogshowmod
\docparam{defaultValue}{The default value, which may be the empty string.} \docparam{defaultValue}{The default value, which may be the empty string.}
\docparam{style}{A dialog style, specifying the buttons (wxOK, wxCANCEL) and an optional wxCENTRE style.} \docparam{style}{A dialog style, specifying the buttons (wxOK, wxCANCEL)
and an optional wxCENTRE style. Additionally, wxTextCtrl styles (such as
{\tt wxTE\_PASSWORD} may be specified here.}
\docparam{pos}{Dialog position.} \docparam{pos}{Dialog position.}

View File

@@ -22,20 +22,23 @@
class WXDLLEXPORT wxTextCtrl; class WXDLLEXPORT wxTextCtrl;
// Handy dialog functions (will be converted into classes at some point)
WXDLLEXPORT_DATA(extern const wxChar*) wxGetTextFromUserPromptStr; WXDLLEXPORT_DATA(extern const wxChar*) wxGetTextFromUserPromptStr;
WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
#define wxTextEntryDialogStyle (wxOK | wxCANCEL | wxCENTRE)
// ----------------------------------------------------------------------------
// wxTextEntryDialog: a dialog with text control, [ok] and [cancel] buttons
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxTextEntryDialog : public wxDialog class WXDLLEXPORT wxTextEntryDialog : public wxDialog
{ {
DECLARE_DYNAMIC_CLASS(wxTextEntryDialog)
public: public:
wxTextEntryDialog(wxWindow *parent, wxTextEntryDialog(wxWindow *parent,
const wxString& message, const wxString& message,
const wxString& caption = wxGetTextFromUserPromptStr, const wxString& caption = wxGetTextFromUserPromptStr,
const wxString& value = wxEmptyString, const wxString& value = wxEmptyString,
long style = wxOK | wxCANCEL | wxCENTRE, long style = wxTextEntryDialogStyle,
const wxPoint& pos = wxDefaultPosition); const wxPoint& pos = wxDefaultPosition);
void SetValue(const wxString& val) { m_value = val; } void SetValue(const wxString& val) { m_value = val; }
@@ -51,6 +54,7 @@ protected:
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxTextEntryDialog)
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -66,5 +70,11 @@ wxGetTextFromUser(const wxString& message,
int y = -1, int y = -1,
bool centre = TRUE); bool centre = TRUE);
wxString WXDLLEXPORT
wxGetPasswordFromUser(const wxString& message,
const wxString& caption = wxGetTextFromUserPromptStr,
const wxString& default_value = wxEmptyString,
wxWindow *parent = (wxWindow *) NULL);
#endif #endif
// __TEXTDLGH_G__ // __TEXTDLGH_G__

View File

@@ -78,13 +78,14 @@ bool MyApp::OnInit(void)
file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L"); file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L");
file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M"); file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M");
file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E"); file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E");
file_menu->Append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P");
file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N"); file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N");
file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-S"); file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-S");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T"); file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O"); file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O");
file_menu->Append(DIALOGS_FILES_OPEN, "&Open files\tCtrl-Q"); file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q");
file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file"); file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file");
file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D"); file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
@@ -233,10 +234,27 @@ void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
wxMessageBox(msg, "Numeric test result", wxOK | icon, this); wxMessageBox(msg, "Numeric test result", wxOK | icon, this);
} }
void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event) ) void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
{ {
wxTextEntryDialog dialog(this, "This is a small sample\nA long, long string to test out the text entrybox", wxString pwd = wxGetPasswordFromUser("Enter password:",
"Please enter a string", "Default value", wxOK|wxCANCEL); "Passowrd entry dialog",
"",
this);
if ( !!pwd )
{
wxMessageBox(wxString::Format("Your password is '%s'", pwd.c_str()),
"Got password", wxOK | wxICON_INFORMATION, this);
}
}
void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
{
wxTextEntryDialog dialog(this,
"This is a small sample\n"
"A long, long string to test out the text entrybox",
"Please enter a string",
"Default value",
wxOK | wxCANCEL);
if (dialog.ShowModal() == wxID_OK) if (dialog.ShowModal() == wxID_OK)
{ {
@@ -386,22 +404,23 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
#endif #endif
EVT_MENU(wxID_EXIT, MyFrame::OnExit) EVT_MENU(wxID_EXIT, MyFrame::OnExit)
END_EVENT_TABLE() END_EVENT_TABLE()

View File

@@ -35,6 +35,7 @@ public:
void MessageBox(wxCommandEvent& event); void MessageBox(wxCommandEvent& event);
void SingleChoice(wxCommandEvent& event); void SingleChoice(wxCommandEvent& event);
void TextEntry(wxCommandEvent& event); void TextEntry(wxCommandEvent& event);
void PasswordEntry(wxCommandEvent& event);
void NumericEntry(wxCommandEvent& event); void NumericEntry(wxCommandEvent& event);
void FileOpen(wxCommandEvent& event); void FileOpen(wxCommandEvent& event);
void FilesOpen(wxCommandEvent& event); void FilesOpen(wxCommandEvent& event);
@@ -64,20 +65,24 @@ public:
// Menu IDs // Menu IDs
#define DIALOGS_CHOOSE_COLOUR 1 enum
#define DIALOGS_CHOOSE_COLOUR_GENERIC 2 {
#define DIALOGS_CHOOSE_FONT 3 DIALOGS_CHOOSE_COLOUR = 1,
#define DIALOGS_CHOOSE_FONT_GENERIC 4 DIALOGS_CHOOSE_COLOUR_GENERIC,
#define DIALOGS_MESSAGE_BOX 5 DIALOGS_CHOOSE_FONT,
#define DIALOGS_SINGLE_CHOICE 6 DIALOGS_CHOOSE_FONT_GENERIC,
#define DIALOGS_TEXT_ENTRY 7 DIALOGS_MESSAGE_BOX,
#define DIALOGS_FILE_OPEN 8 DIALOGS_SINGLE_CHOICE,
#define DIALOGS_FILES_OPEN 9 DIALOGS_TEXT_ENTRY,
#define DIALOGS_FILE_SAVE 10 DIALOGS_PASSWORD_ENTRY,
#define DIALOGS_DIR_CHOOSE 11 DIALOGS_FILE_OPEN,
#define DIALOGS_TIP 12 DIALOGS_FILES_OPEN,
#define DIALOGS_NUM_ENTRY 13 DIALOGS_FILE_SAVE,
#define DIALOGS_LOG_DIALOG 14 DIALOGS_DIR_CHOOSE,
DIALOGS_TIP,
DIALOGS_NUM_ENTRY,
DIALOGS_LOG_DIALOG
};
#endif #endif

View File

@@ -87,7 +87,9 @@ wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 ); topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
// 2) text ctrl // 2) text ctrl
m_textctrl = new wxTextCtrl(this, wxID_TEXT, value, wxDefaultPosition, wxSize(300, -1)); m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
wxDefaultPosition, wxSize(300, -1),
style & ~wxTextEntryDialogStyle);
topsizer->Add( m_textctrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 ); topsizer->Add( m_textctrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 );
#if wxUSE_STATLINE #if wxUSE_STATLINE