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 bool wxTextEntryDialog::Create(wxWindow
*parent
,
69 const wxString
& message
,
70 const wxString
& caption
,
71 const wxString
& value
,
75 if ( !wxDialog::Create(GetParentForModalDialog(parent
, style
),
78 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
) )
83 m_dialogStyle
= style
;
88 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
90 wxSizerFlags flagsBorder2
;
91 flagsBorder2
.DoubleBorder();
95 topsizer
->Add(CreateTextSizer(message
), flagsBorder2
);
99 m_textctrl
= new wxTextCtrl(this, wxID_TEXT
, value
,
100 wxDefaultPosition
, wxSize(300, wxDefaultCoord
),
101 style
& ~wxTextEntryDialogStyle
);
103 topsizer
->Add(m_textctrl
,
104 wxSizerFlags(style
& wxTE_MULTILINE
? 1 : 0).
106 TripleBorder(wxLEFT
| wxRIGHT
));
109 wxSizer
*buttonSizer
= CreateSeparatedButtonSizer(style
& (wxOK
| wxCANCEL
));
112 topsizer
->Add(buttonSizer
, wxSizerFlags(flagsBorder2
).Expand());
115 SetAutoLayout( true );
116 SetSizer( topsizer
);
118 topsizer
->SetSizeHints( this );
119 topsizer
->Fit( this );
121 if ( style
& wxCENTRE
)
124 m_textctrl
->SelectAll();
125 m_textctrl
->SetFocus();
132 bool wxTextEntryDialog::TransferDataToWindow()
134 m_textctrl
->SetValue(m_value
);
136 return wxDialog::TransferDataToWindow();
139 bool wxTextEntryDialog::TransferDataFromWindow()
141 m_value
= m_textctrl
->GetValue();
143 return wxDialog::TransferDataFromWindow();
146 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
148 if ( Validate() && TransferDataFromWindow() )
154 void wxTextEntryDialog::SetMaxLength(unsigned long len
)
156 m_textctrl
->SetMaxLength(len
);
159 void wxTextEntryDialog::SetValue(const wxString
& val
)
163 m_textctrl
->SetValue(val
);
168 #if WXWIN_COMPATIBILITY_2_8
169 void wxTextEntryDialog::SetTextValidator( long style
)
171 SetTextValidator((wxTextValidatorStyle
)style
);
175 void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style
)
177 SetTextValidator(wxTextValidator(style
));
180 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
182 m_textctrl
->SetValidator( validator
);
185 #endif // wxUSE_VALIDATORS
187 // ----------------------------------------------------------------------------
188 // wxPasswordEntryDialog
189 // ----------------------------------------------------------------------------
191 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
193 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
194 const wxString
& message
,
195 const wxString
& caption
,
196 const wxString
& value
,
199 : wxTextEntryDialog(parent
, message
, caption
, value
,
200 style
| wxTE_PASSWORD
, pos
)
202 // Only change from wxTextEntryDialog is the password style
205 #endif // wxUSE_TEXTDLG