1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/generic/textdlgg.h 3 // Purpose: wxTextEntryDialog class 4 // Author: Julian Smart 5 // Modified by: 6 // Created: 01/02/97 7 // Copyright: (c) Julian Smart 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_TEXTDLGG_H_ 12 #define _WX_TEXTDLGG_H_ 13 14 #include "wx/defs.h" 15 16 #if wxUSE_TEXTDLG 17 18 #include "wx/dialog.h" 19 20 #if wxUSE_VALIDATORS 21 #include "wx/valtext.h" 22 #include "wx/textctrl.h" 23 #endif 24 25 class WXDLLIMPEXP_FWD_CORE wxTextCtrl; 26 27 extern WXDLLIMPEXP_DATA_CORE(const char) wxGetTextFromUserPromptStr[]; 28 extern WXDLLIMPEXP_DATA_CORE(const char) wxGetPasswordFromUserPromptStr[]; 29 30 #define wxTextEntryDialogStyle (wxOK | wxCANCEL | wxCENTRE) 31 32 // ---------------------------------------------------------------------------- 33 // wxTextEntryDialog: a dialog with text control, [ok] and [cancel] buttons 34 // ---------------------------------------------------------------------------- 35 36 class WXDLLIMPEXP_CORE wxTextEntryDialog : public wxDialog 37 { 38 public: wxTextEntryDialog()39 wxTextEntryDialog() 40 { 41 m_textctrl = NULL; 42 m_dialogStyle = 0; 43 } 44 45 wxTextEntryDialog(wxWindow *parent, 46 const wxString& message, 47 const wxString& caption = wxASCII_STR(wxGetTextFromUserPromptStr), 48 const wxString& value = wxEmptyString, 49 long style = wxTextEntryDialogStyle, 50 const wxPoint& pos = wxDefaultPosition) 51 { 52 Create(parent, message, caption, value, style, pos); 53 } 54 55 bool Create(wxWindow *parent, 56 const wxString& message, 57 const wxString& caption = wxASCII_STR(wxGetTextFromUserPromptStr), 58 const wxString& value = wxEmptyString, 59 long style = wxTextEntryDialogStyle, 60 const wxPoint& pos = wxDefaultPosition); 61 62 void SetValue(const wxString& val); GetValue()63 wxString GetValue() const { return m_value; } 64 65 void SetMaxLength(unsigned long len); 66 67 void ForceUpper(); 68 69 #if wxUSE_VALIDATORS 70 void SetTextValidator( const wxTextValidator& validator ); 71 #if WXWIN_COMPATIBILITY_2_8 72 wxDEPRECATED( void SetTextValidator( long style ) ); 73 #endif 74 void SetTextValidator( wxTextValidatorStyle style = wxFILTER_NONE ); GetTextValidator()75 wxTextValidator* GetTextValidator() { return (wxTextValidator*)m_textctrl->GetValidator(); } 76 #endif // wxUSE_VALIDATORS 77 78 virtual bool TransferDataToWindow() wxOVERRIDE; 79 virtual bool TransferDataFromWindow() wxOVERRIDE; 80 81 // implementation only 82 void OnOK(wxCommandEvent& event); 83 84 protected: 85 wxTextCtrl *m_textctrl; 86 wxString m_value; 87 long m_dialogStyle; 88 89 private: 90 wxDECLARE_EVENT_TABLE(); 91 wxDECLARE_DYNAMIC_CLASS(wxTextEntryDialog); 92 wxDECLARE_NO_COPY_CLASS(wxTextEntryDialog); 93 }; 94 95 // ---------------------------------------------------------------------------- 96 // wxPasswordEntryDialog: dialog with password control, [ok] and [cancel] 97 // ---------------------------------------------------------------------------- 98 99 class WXDLLIMPEXP_CORE wxPasswordEntryDialog : public wxTextEntryDialog 100 { 101 public: wxPasswordEntryDialog()102 wxPasswordEntryDialog() { } 103 wxPasswordEntryDialog(wxWindow *parent, 104 const wxString& message, 105 const wxString& caption = wxASCII_STR(wxGetPasswordFromUserPromptStr), 106 const wxString& value = wxEmptyString, 107 long style = wxTextEntryDialogStyle, 108 const wxPoint& pos = wxDefaultPosition) 109 { 110 Create(parent, message, caption, value, style, pos); 111 } 112 113 bool Create(wxWindow *parent, 114 const wxString& message, 115 const wxString& caption = wxASCII_STR(wxGetPasswordFromUserPromptStr), 116 const wxString& value = wxEmptyString, 117 long style = wxTextEntryDialogStyle, 118 const wxPoint& pos = wxDefaultPosition); 119 120 121 private: 122 wxDECLARE_DYNAMIC_CLASS(wxPasswordEntryDialog); 123 wxDECLARE_NO_COPY_CLASS(wxPasswordEntryDialog); 124 }; 125 126 // ---------------------------------------------------------------------------- 127 // function to get a string from user 128 // ---------------------------------------------------------------------------- 129 130 WXDLLIMPEXP_CORE wxString 131 wxGetTextFromUser(const wxString& message, 132 const wxString& caption = wxASCII_STR(wxGetTextFromUserPromptStr), 133 const wxString& default_value = wxEmptyString, 134 wxWindow *parent = NULL, 135 wxCoord x = wxDefaultCoord, 136 wxCoord y = wxDefaultCoord, 137 bool centre = true); 138 139 WXDLLIMPEXP_CORE wxString 140 wxGetPasswordFromUser(const wxString& message, 141 const wxString& caption = wxASCII_STR(wxGetPasswordFromUserPromptStr), 142 const wxString& default_value = wxEmptyString, 143 wxWindow *parent = NULL, 144 wxCoord x = wxDefaultCoord, 145 wxCoord y = wxDefaultCoord, 146 bool centre = true); 147 148 #endif 149 // wxUSE_TEXTDLG 150 #endif // _WX_TEXTDLGG_H_ 151