1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/textdlgg.cpp
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
28 #include "wx/generic/textdlgg.h"
32 #include "wx/dialog.h"
33 #include "wx/button.h"
34 #include "wx/stattext.h"
35 #include "wx/textctrl.h"
41 #include "wx/statline.h"
44 const char wxGetTextFromUserPromptStr
[] = "Input Text";
45 const char wxGetPasswordFromUserPromptStr
[] = "Enter Password";
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 static const int wxID_TEXT
= 3000;
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
62 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
65 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
67 bool wxTextEntryDialog::Create(wxWindow
*parent
,
68 const wxString
& message
,
69 const wxString
& caption
,
70 const wxString
& value
,
74 if ( !wxDialog::Create(GetParentForModalDialog(parent
, style
),
77 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
) )
82 m_dialogStyle
= style
;
87 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
89 wxSizerFlags flagsBorder2
;
90 flagsBorder2
.DoubleBorder();
94 topsizer
->Add(CreateTextSizer(message
), flagsBorder2
);
98 m_textctrl
= new wxTextCtrl(this, wxID_TEXT
, value
,
99 wxDefaultPosition
, wxSize(300, wxDefaultCoord
),
100 style
& ~wxTextEntryDialogStyle
);
102 topsizer
->Add(m_textctrl
,
103 wxSizerFlags(style
& wxTE_MULTILINE
? 1 : 0).
105 TripleBorder(wxLEFT
| wxRIGHT
));
108 wxSizer
*buttonSizer
= CreateSeparatedButtonSizer(style
& (wxOK
| wxCANCEL
));
111 topsizer
->Add(buttonSizer
, wxSizerFlags(flagsBorder2
).Expand());
114 SetAutoLayout( true );
115 SetSizer( topsizer
);
117 topsizer
->SetSizeHints( this );
118 topsizer
->Fit( this );
120 if ( style
& wxCENTRE
)
123 m_textctrl
->SelectAll();
124 m_textctrl
->SetFocus();
131 bool wxTextEntryDialog::TransferDataToWindow()
133 m_textctrl
->SetValue(m_value
);
135 return wxDialog::TransferDataToWindow();
138 bool wxTextEntryDialog::TransferDataFromWindow()
140 m_value
= m_textctrl
->GetValue();
142 return wxDialog::TransferDataFromWindow();
145 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
147 if ( Validate() && TransferDataFromWindow() )
153 void wxTextEntryDialog::SetMaxLength(unsigned long len
)
155 m_textctrl
->SetMaxLength(len
);
158 void wxTextEntryDialog::SetValue(const wxString
& val
)
162 m_textctrl
->SetValue(val
);
167 #if WXWIN_COMPATIBILITY_2_8
168 void wxTextEntryDialog::SetTextValidator( long style
)
170 SetTextValidator((wxTextValidatorStyle
)style
);
174 void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style
)
176 SetTextValidator(wxTextValidator(style
));
179 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
181 m_textctrl
->SetValidator( validator
);
184 #endif // wxUSE_VALIDATORS
186 // ----------------------------------------------------------------------------
187 // wxPasswordEntryDialog
188 // ----------------------------------------------------------------------------
190 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
192 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
193 const wxString
& message
,
194 const wxString
& caption
,
195 const wxString
& value
,
198 : wxTextEntryDialog(parent
, message
, caption
, value
,
199 style
| wxTE_PASSWORD
, pos
)
201 // Only change from wxTextEntryDialog is the password style
204 #endif // wxUSE_TEXTDLG