]>
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 | ||
4a2e5ee8 RD |
45 | const wxChar wxGetTextFromUserPromptStr[] = wxT("Input Text"); |
46 | const wxChar wxGetPasswordFromUserPromptStr[] = wxT("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 | |
c50f1fb9 VZ |
68 | wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, |
69 | const wxString& message, | |
70 | const wxString& caption, | |
71 | const wxString& value, | |
72 | long style, | |
73 | const wxPoint& pos) | |
ca65c044 | 74 | : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize, |
1c067fe3 | 75 | wxDEFAULT_DIALOG_STYLE), |
c50f1fb9 | 76 | m_value(value) |
c801d85f | 77 | { |
92afa2b1 RR |
78 | m_dialogStyle = style; |
79 | m_value = value; | |
80 | ||
81 | wxBeginBusyCursor(); | |
479cd5de | 82 | |
92afa2b1 RR |
83 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); |
84 | ||
bd9f3519 VZ |
85 | wxSizerFlags flagsBorder2; |
86 | flagsBorder2.DoubleBorder(); | |
87 | ||
132422c4 | 88 | #if wxUSE_STATTEXT |
92afa2b1 | 89 | // 1) text message |
bd9f3519 | 90 | topsizer->Add(CreateTextSizer(message), flagsBorder2); |
897b24cf | 91 | #endif |
479cd5de | 92 | |
92afa2b1 | 93 | // 2) text ctrl |
a294c6d5 | 94 | m_textctrl = new wxTextCtrl(this, wxID_TEXT, value, |
422d0ff0 | 95 | wxDefaultPosition, wxSize(300, wxDefaultCoord), |
a294c6d5 | 96 | style & ~wxTextEntryDialogStyle); |
bd9f3519 VZ |
97 | |
98 | topsizer->Add(m_textctrl, | |
99 | wxSizerFlags(style & wxTE_MULTILINE ? 1 : 0). | |
100 | Expand(). | |
101 | TripleBorder(wxLEFT | wxRIGHT)); | |
92afa2b1 | 102 | |
fc0d5b6b JS |
103 | #if wxUSE_VALIDATORS |
104 | wxTextValidator validator( wxFILTER_NONE, &m_value ); | |
105 | m_textctrl->SetValidator( validator ); | |
897b24cf | 106 | #endif // wxUSE_VALIDATORS |
92afa2b1 | 107 | |
897b24cf | 108 | // 3) buttons if any |
bd9f3519 VZ |
109 | wxSizer *buttonSizer = CreateSeparatedButtonSizer(style & ButtonSizerFlags); |
110 | if ( buttonSizer ) | |
897b24cf | 111 | { |
bd9f3519 | 112 | topsizer->Add(buttonSizer, wxSizerFlags(flagsBorder2).Expand()); |
897b24cf | 113 | } |
0d1f53ca | 114 | |
ca65c044 | 115 | SetAutoLayout( true ); |
8b17ba72 | 116 | SetSizer( topsizer ); |
479cd5de | 117 | |
92afa2b1 RR |
118 | topsizer->SetSizeHints( this ); |
119 | topsizer->Fit( this ); | |
92afa2b1 | 120 | |
01e13147 | 121 | if ( style & wxCENTRE ) |
13d13a9e | 122 | Centre( wxBOTH ); |
c801d85f | 123 | |
19de4eec | 124 | m_textctrl->SetSelection(-1, -1); |
c50f1fb9 | 125 | m_textctrl->SetFocus(); |
92afa2b1 RR |
126 | |
127 | wxEndBusyCursor(); | |
c801d85f KB |
128 | } |
129 | ||
130 | void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) | |
131 | { | |
fc0d5b6b | 132 | #if wxUSE_VALIDATORS |
ca65c044 | 133 | if( Validate() && TransferDataFromWindow() ) |
fc0d5b6b JS |
134 | { |
135 | EndModal( wxID_OK ); | |
136 | } | |
137 | #else | |
c50f1fb9 | 138 | m_value = m_textctrl->GetValue(); |
c801d85f | 139 | |
c50f1fb9 | 140 | EndModal(wxID_OK); |
fc0d5b6b JS |
141 | #endif |
142 | // wxUSE_VALIDATORS | |
c801d85f | 143 | } |
1e6feb95 | 144 | |
a8f6ef51 VZ |
145 | void wxTextEntryDialog::SetValue(const wxString& val) |
146 | { | |
147 | m_value = val; | |
148 | ||
149 | m_textctrl->SetValue(val); | |
150 | } | |
151 | ||
fc0d5b6b JS |
152 | #if wxUSE_VALIDATORS |
153 | void wxTextEntryDialog::SetTextValidator( long style ) | |
154 | { | |
155 | wxTextValidator validator( style, &m_value ); | |
156 | m_textctrl->SetValidator( validator ); | |
157 | } | |
158 | ||
fbfb8bcc | 159 | void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator ) |
fc0d5b6b JS |
160 | { |
161 | m_textctrl->SetValidator( validator ); | |
162 | } | |
163 | ||
164 | #endif | |
165 | // wxUSE_VALIDATORS | |
166 | ||
e9f4948e KH |
167 | // ---------------------------------------------------------------------------- |
168 | // wxPasswordEntryDialog | |
169 | // ---------------------------------------------------------------------------- | |
170 | ||
171 | IMPLEMENT_CLASS(wxPasswordEntryDialog, wxTextEntryDialog) | |
172 | ||
173 | wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow *parent, | |
174 | const wxString& message, | |
175 | const wxString& caption, | |
176 | const wxString& value, | |
177 | long style, | |
178 | const wxPoint& pos) | |
179 | : wxTextEntryDialog(parent, message, caption, value, | |
180 | style | wxTE_PASSWORD, pos) | |
181 | { | |
182 | // Only change from wxTextEntryDialog is the password style | |
183 | } | |
184 | ||
1e6feb95 | 185 | #endif // wxUSE_TEXTDLG |