1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/textdlgg.cpp
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/generic/textdlgg.h"
33 #include "wx/dialog.h"
34 #include "wx/button.h"
35 #include "wx/stattext.h"
36 #include "wx/textctrl.h"
42 #include "wx/statline.h"
45 const char wxGetTextFromUserPromptStr
[] = "Input Text";
46 const char wxGetPasswordFromUserPromptStr
[] = "Enter Password";
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 static const int wxID_TEXT
= 3000;
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
63 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
66 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
68 wxTextEntryDialog::wxTextEntryDialog(wxWindow
*parent
,
69 const wxString
& message
,
70 const wxString
& caption
,
71 const wxString
& value
,
74 : wxDialog(GetParentForModalDialog(parent
),
75 wxID_ANY
, caption
, pos
, wxDefaultSize
,
76 wxDEFAULT_DIALOG_STYLE
),
79 m_dialogStyle
= style
;
84 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
86 wxSizerFlags flagsBorder2
;
87 flagsBorder2
.DoubleBorder();
91 topsizer
->Add(CreateTextSizer(message
), flagsBorder2
);
95 m_textctrl
= new wxTextCtrl(this, wxID_TEXT
, value
,
96 wxDefaultPosition
, wxSize(300, wxDefaultCoord
),
97 style
& ~wxTextEntryDialogStyle
);
99 topsizer
->Add(m_textctrl
,
100 wxSizerFlags(style
& wxTE_MULTILINE
? 1 : 0).
102 TripleBorder(wxLEFT
| wxRIGHT
));
105 wxTextValidator
validator( wxFILTER_NONE
, &m_value
);
106 m_textctrl
->SetValidator( validator
);
107 #endif // wxUSE_VALIDATORS
110 wxSizer
*buttonSizer
= CreateSeparatedButtonSizer(style
& ButtonSizerFlags
);
113 topsizer
->Add(buttonSizer
, wxSizerFlags(flagsBorder2
).Expand());
116 SetAutoLayout( true );
117 SetSizer( topsizer
);
119 topsizer
->SetSizeHints( this );
120 topsizer
->Fit( this );
122 if ( style
& wxCENTRE
)
125 m_textctrl
->SetSelection(-1, -1);
126 m_textctrl
->SetFocus();
131 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
134 if( Validate() && TransferDataFromWindow() )
139 m_value
= m_textctrl
->GetValue();
146 void wxTextEntryDialog::SetValue(const wxString
& val
)
150 m_textctrl
->SetValue(val
);
155 #if WXWIN_COMPATIBILITY_2_8
156 void wxTextEntryDialog::SetTextValidator( long style
)
158 SetTextValidator((wxTextValidatorStyle
)style
);
162 void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style
)
164 wxTextValidator
validator( style
, &m_value
);
165 m_textctrl
->SetValidator( validator
);
168 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
170 m_textctrl
->SetValidator( validator
);
176 // ----------------------------------------------------------------------------
177 // wxPasswordEntryDialog
178 // ----------------------------------------------------------------------------
180 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
182 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
183 const wxString
& message
,
184 const wxString
& caption
,
185 const wxString
& value
,
188 : wxTextEntryDialog(parent
, message
, caption
, value
,
189 style
| wxTE_PASSWORD
, pos
)
191 // Only change from wxTextEntryDialog is the password style
194 #endif // wxUSE_TEXTDLG