]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
897b24cf | 2 | // Name: src/generic/textdlgg.cpp |
c801d85f KB |
3 | // Purpose: wxTextEntryDialog |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
6aa89a22 | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
c50f1fb9 VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
c801d85f KB |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
c50f1fb9 | 23 | #pragma hdrstop |
c801d85f KB |
24 | #endif |
25 | ||
1e6feb95 VZ |
26 | #if wxUSE_TEXTDLG |
27 | ||
e7445ff8 PC |
28 | #include "wx/generic/textdlgg.h" |
29 | ||
c801d85f | 30 | #ifndef WX_PRECOMP |
c50f1fb9 VZ |
31 | #include "wx/utils.h" |
32 | #include "wx/dialog.h" | |
33 | #include "wx/button.h" | |
34 | #include "wx/stattext.h" | |
35 | #include "wx/textctrl.h" | |
36 | #include "wx/intl.h" | |
92afa2b1 | 37 | #include "wx/sizer.h" |
dcf924a3 RR |
38 | #endif |
39 | ||
40 | #if wxUSE_STATLINE | |
c50f1fb9 | 41 | #include "wx/statline.h" |
c801d85f KB |
42 | #endif |
43 | ||
f36e602b VZ |
44 | const char wxGetTextFromUserPromptStr[] = "Input Text"; |
45 | const char wxGetPasswordFromUserPromptStr[] = "Enter Password"; | |
c801d85f | 46 | |
c50f1fb9 VZ |
47 | // ---------------------------------------------------------------------------- |
48 | // constants | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
c49245f8 | 51 | static const int wxID_TEXT = 3000; |
dcf924a3 | 52 | |
c50f1fb9 VZ |
53 | // ============================================================================ |
54 | // implementation | |
55 | // ============================================================================ | |
56 | ||
57 | // ---------------------------------------------------------------------------- | |
c801d85f | 58 | // wxTextEntryDialog |
c50f1fb9 | 59 | // ---------------------------------------------------------------------------- |
c801d85f | 60 | |
c801d85f | 61 | BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog) |
c50f1fb9 | 62 | EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK) |
c801d85f KB |
63 | END_EVENT_TABLE() |
64 | ||
65 | IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog) | |
c801d85f | 66 | |
b8d6be7f | 67 | bool wxTextEntryDialog::Create(wxWindow *parent, |
c50f1fb9 VZ |
68 | const wxString& message, |
69 | const wxString& caption, | |
70 | const wxString& value, | |
71 | long style, | |
72 | const wxPoint& pos) | |
c801d85f | 73 | { |
b8d6be7f VZ |
74 | if ( !wxDialog::Create(GetParentForModalDialog(parent, style), |
75 | wxID_ANY, caption, | |
76 | pos, wxDefaultSize, | |
97c15a53 | 77 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) ) |
b8d6be7f VZ |
78 | { |
79 | return false; | |
80 | } | |
81 | ||
92afa2b1 RR |
82 | m_dialogStyle = style; |
83 | m_value = value; | |
84 | ||
85 | wxBeginBusyCursor(); | |
479cd5de | 86 | |
92afa2b1 RR |
87 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); |
88 | ||
bd9f3519 VZ |
89 | wxSizerFlags flagsBorder2; |
90 | flagsBorder2.DoubleBorder(); | |
91 | ||
132422c4 | 92 | #if wxUSE_STATTEXT |
92afa2b1 | 93 | // 1) text message |
bd9f3519 | 94 | topsizer->Add(CreateTextSizer(message), flagsBorder2); |
897b24cf | 95 | #endif |
479cd5de | 96 | |
92afa2b1 | 97 | // 2) text ctrl |
a294c6d5 | 98 | m_textctrl = new wxTextCtrl(this, wxID_TEXT, value, |
422d0ff0 | 99 | wxDefaultPosition, wxSize(300, wxDefaultCoord), |
a294c6d5 | 100 | style & ~wxTextEntryDialogStyle); |
bd9f3519 VZ |
101 | |
102 | topsizer->Add(m_textctrl, | |
103 | wxSizerFlags(style & wxTE_MULTILINE ? 1 : 0). | |
104 | Expand(). | |
105 | TripleBorder(wxLEFT | wxRIGHT)); | |
92afa2b1 | 106 | |
897b24cf | 107 | // 3) buttons if any |
12a124dd | 108 | wxSizer *buttonSizer = CreateSeparatedButtonSizer(style & (wxOK | wxCANCEL)); |
bd9f3519 | 109 | if ( buttonSizer ) |
897b24cf | 110 | { |
bd9f3519 | 111 | topsizer->Add(buttonSizer, wxSizerFlags(flagsBorder2).Expand()); |
897b24cf | 112 | } |
0d1f53ca | 113 | |
ca65c044 | 114 | SetAutoLayout( true ); |
8b17ba72 | 115 | SetSizer( topsizer ); |
479cd5de | 116 | |
92afa2b1 RR |
117 | topsizer->SetSizeHints( this ); |
118 | topsizer->Fit( this ); | |
92afa2b1 | 119 | |
01e13147 | 120 | if ( style & wxCENTRE ) |
13d13a9e | 121 | Centre( wxBOTH ); |
c801d85f | 122 | |
70680b61 | 123 | m_textctrl->SelectAll(); |
c50f1fb9 | 124 | m_textctrl->SetFocus(); |
92afa2b1 RR |
125 | |
126 | wxEndBusyCursor(); | |
b8d6be7f VZ |
127 | |
128 | return true; | |
c801d85f KB |
129 | } |
130 | ||
42fe16e5 VZ |
131 | bool wxTextEntryDialog::TransferDataToWindow() |
132 | { | |
133 | m_textctrl->SetValue(m_value); | |
134 | ||
135 | return wxDialog::TransferDataToWindow(); | |
136 | } | |
137 | ||
138 | bool wxTextEntryDialog::TransferDataFromWindow() | |
139 | { | |
140 | m_value = m_textctrl->GetValue(); | |
141 | ||
142 | return wxDialog::TransferDataFromWindow(); | |
143 | } | |
144 | ||
c801d85f KB |
145 | void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) |
146 | { | |
42fe16e5 | 147 | if ( Validate() && TransferDataFromWindow() ) |
fc0d5b6b JS |
148 | { |
149 | EndModal( wxID_OK ); | |
150 | } | |
c801d85f | 151 | } |
1e6feb95 | 152 | |
62a58fbe VZ |
153 | void wxTextEntryDialog::SetMaxLength(unsigned long len) |
154 | { | |
155 | m_textctrl->SetMaxLength(len); | |
156 | } | |
157 | ||
a8f6ef51 VZ |
158 | void wxTextEntryDialog::SetValue(const wxString& val) |
159 | { | |
160 | m_value = val; | |
161 | ||
162 | m_textctrl->SetValue(val); | |
163 | } | |
164 | ||
fc0d5b6b | 165 | #if wxUSE_VALIDATORS |
40ae9600 FM |
166 | |
167 | #if WXWIN_COMPATIBILITY_2_8 | |
fc0d5b6b | 168 | void wxTextEntryDialog::SetTextValidator( long style ) |
40ae9600 FM |
169 | { |
170 | SetTextValidator((wxTextValidatorStyle)style); | |
171 | } | |
172 | #endif | |
173 | ||
174 | void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style ) | |
fc0d5b6b | 175 | { |
42fe16e5 | 176 | SetTextValidator(wxTextValidator(style)); |
fc0d5b6b JS |
177 | } |
178 | ||
fbfb8bcc | 179 | void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator ) |
fc0d5b6b JS |
180 | { |
181 | m_textctrl->SetValidator( validator ); | |
182 | } | |
183 | ||
42fe16e5 | 184 | #endif // wxUSE_VALIDATORS |
fc0d5b6b | 185 | |
e9f4948e KH |
186 | // ---------------------------------------------------------------------------- |
187 | // wxPasswordEntryDialog | |
188 | // ---------------------------------------------------------------------------- | |
189 | ||
190 | IMPLEMENT_CLASS(wxPasswordEntryDialog, wxTextEntryDialog) | |
191 | ||
192 | wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow *parent, | |
193 | const wxString& message, | |
194 | const wxString& caption, | |
195 | const wxString& value, | |
196 | long style, | |
197 | const wxPoint& pos) | |
198 | : wxTextEntryDialog(parent, message, caption, value, | |
199 | style | wxTE_PASSWORD, pos) | |
200 | { | |
201 | // Only change from wxTextEntryDialog is the password style | |
202 | } | |
203 | ||
1e6feb95 | 204 | #endif // wxUSE_TEXTDLG |