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