]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: textdlgg.cpp | |
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 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c50f1fb9 | 21 | #pragma implementation "textdlgg.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
c50f1fb9 | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_TEXTDLG |
32 | ||
c801d85f | 33 | #ifndef WX_PRECOMP |
c50f1fb9 VZ |
34 | #include "wx/utils.h" |
35 | #include "wx/dialog.h" | |
36 | #include "wx/button.h" | |
37 | #include "wx/stattext.h" | |
38 | #include "wx/textctrl.h" | |
39 | #include "wx/intl.h" | |
92afa2b1 | 40 | #include "wx/sizer.h" |
dcf924a3 RR |
41 | #endif |
42 | ||
43 | #if wxUSE_STATLINE | |
c50f1fb9 | 44 | #include "wx/statline.h" |
c801d85f KB |
45 | #endif |
46 | ||
47 | #include "wx/generic/textdlgg.h" | |
48 | ||
c50f1fb9 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // constants | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
c49245f8 | 53 | static const int wxID_TEXT = 3000; |
dcf924a3 | 54 | |
0d1f53ca WS |
55 | // --------------------------------------------------------------------------- |
56 | // macros | |
57 | // --------------------------------------------------------------------------- | |
58 | ||
59 | /* Macro for avoiding #ifdefs when value have to be different depending on size of | |
9a357011 | 60 | device we display on - take it from something like wxDesktopPolicy in the future |
0d1f53ca WS |
61 | */ |
62 | ||
63 | #if defined(__SMARTPHONE__) | |
64 | #define wxLARGESMALL(large,small) small | |
65 | #else | |
66 | #define wxLARGESMALL(large,small) large | |
67 | #endif | |
68 | ||
c50f1fb9 VZ |
69 | // ============================================================================ |
70 | // implementation | |
71 | // ============================================================================ | |
72 | ||
73 | // ---------------------------------------------------------------------------- | |
c801d85f | 74 | // wxTextEntryDialog |
c50f1fb9 | 75 | // ---------------------------------------------------------------------------- |
c801d85f | 76 | |
c801d85f | 77 | BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog) |
c50f1fb9 | 78 | EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK) |
c801d85f KB |
79 | END_EVENT_TABLE() |
80 | ||
81 | IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog) | |
c801d85f | 82 | |
c50f1fb9 VZ |
83 | wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, |
84 | const wxString& message, | |
85 | const wxString& caption, | |
86 | const wxString& value, | |
87 | long style, | |
88 | const wxPoint& pos) | |
ca65c044 | 89 | : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize, |
c50f1fb9 VZ |
90 | wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL), |
91 | m_value(value) | |
c801d85f | 92 | { |
92afa2b1 RR |
93 | m_dialogStyle = style; |
94 | m_value = value; | |
95 | ||
96 | wxBeginBusyCursor(); | |
479cd5de | 97 | |
92afa2b1 RR |
98 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); |
99 | ||
100 | // 1) text message | |
0d1f53ca | 101 | topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(10,0) ); |
479cd5de | 102 | |
92afa2b1 | 103 | // 2) text ctrl |
a294c6d5 | 104 | m_textctrl = new wxTextCtrl(this, wxID_TEXT, value, |
422d0ff0 | 105 | wxDefaultPosition, wxSize(300, wxDefaultCoord), |
a294c6d5 | 106 | style & ~wxTextEntryDialogStyle); |
0d1f53ca | 107 | topsizer->Add( m_textctrl, 1, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(15,0) ); |
92afa2b1 | 108 | |
fc0d5b6b JS |
109 | #if wxUSE_VALIDATORS |
110 | wxTextValidator validator( wxFILTER_NONE, &m_value ); | |
111 | m_textctrl->SetValidator( validator ); | |
112 | #endif | |
113 | // wxUSE_VALIDATORS | |
114 | ||
9a357011 | 115 | // smart phones does not support or do not waste space for wxButtons |
0d1f53ca WS |
116 | #ifdef __SMARTPHONE__ |
117 | ||
118 | SetRightMenu(wxID_CANCEL, _("Cancel")); | |
119 | ||
120 | #else // __SMARTPHONE__/!__SMARTPHONE__ | |
121 | ||
92afa2b1 RR |
122 | #if wxUSE_STATLINE |
123 | // 3) static line | |
ca65c044 | 124 | topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); |
92afa2b1 RR |
125 | #endif |
126 | ||
127 | // 4) buttons | |
128 | topsizer->Add( CreateButtonSizer( style ), 0, wxCENTRE | wxALL, 10 ); | |
479cd5de | 129 | |
0d1f53ca WS |
130 | #endif // !__SMARTPHONE__ |
131 | ||
ca65c044 | 132 | SetAutoLayout( true ); |
8b17ba72 | 133 | SetSizer( topsizer ); |
479cd5de | 134 | |
92afa2b1 RR |
135 | topsizer->SetSizeHints( this ); |
136 | topsizer->Fit( this ); | |
92afa2b1 | 137 | |
01e13147 | 138 | if ( style & wxCENTRE ) |
13d13a9e | 139 | Centre( wxBOTH ); |
c801d85f | 140 | |
19de4eec | 141 | m_textctrl->SetSelection(-1, -1); |
c50f1fb9 | 142 | m_textctrl->SetFocus(); |
92afa2b1 RR |
143 | |
144 | wxEndBusyCursor(); | |
c801d85f KB |
145 | } |
146 | ||
147 | void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) | |
148 | { | |
fc0d5b6b | 149 | #if wxUSE_VALIDATORS |
ca65c044 | 150 | if( Validate() && TransferDataFromWindow() ) |
fc0d5b6b JS |
151 | { |
152 | EndModal( wxID_OK ); | |
153 | } | |
154 | #else | |
c50f1fb9 | 155 | m_value = m_textctrl->GetValue(); |
c801d85f | 156 | |
c50f1fb9 | 157 | EndModal(wxID_OK); |
fc0d5b6b JS |
158 | #endif |
159 | // wxUSE_VALIDATORS | |
c801d85f | 160 | } |
1e6feb95 | 161 | |
a8f6ef51 VZ |
162 | void wxTextEntryDialog::SetValue(const wxString& val) |
163 | { | |
164 | m_value = val; | |
165 | ||
166 | m_textctrl->SetValue(val); | |
167 | } | |
168 | ||
fc0d5b6b JS |
169 | #if wxUSE_VALIDATORS |
170 | void wxTextEntryDialog::SetTextValidator( long style ) | |
171 | { | |
172 | wxTextValidator validator( style, &m_value ); | |
173 | m_textctrl->SetValidator( validator ); | |
174 | } | |
175 | ||
176 | void wxTextEntryDialog::SetTextValidator( wxTextValidator& validator ) | |
177 | { | |
178 | m_textctrl->SetValidator( validator ); | |
179 | } | |
180 | ||
181 | #endif | |
182 | // wxUSE_VALIDATORS | |
183 | ||
e9f4948e KH |
184 | // ---------------------------------------------------------------------------- |
185 | // wxPasswordEntryDialog | |
186 | // ---------------------------------------------------------------------------- | |
187 | ||
188 | IMPLEMENT_CLASS(wxPasswordEntryDialog, wxTextEntryDialog) | |
189 | ||
190 | wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow *parent, | |
191 | const wxString& message, | |
192 | const wxString& caption, | |
193 | const wxString& value, | |
194 | long style, | |
195 | const wxPoint& pos) | |
196 | : wxTextEntryDialog(parent, message, caption, value, | |
197 | style | wxTE_PASSWORD, pos) | |
198 | { | |
199 | // Only change from wxTextEntryDialog is the password style | |
200 | } | |
201 | ||
1e6feb95 | 202 | #endif // wxUSE_TEXTDLG |