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