]> git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
Include wx/slider.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / generic / textdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/textdlgg.cpp
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_TEXTDLG
28
29 #include "wx/generic/textdlgg.h"
30
31 #ifndef WX_PRECOMP
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"
38 #include "wx/sizer.h"
39 #endif
40
41 #if wxUSE_STATLINE
42 #include "wx/statline.h"
43 #endif
44
45 const wxChar wxGetTextFromUserPromptStr[] = wxT("Input Text");
46 const wxChar wxGetPasswordFromUserPromptStr[] = wxT("Enter Password");
47
48 // ----------------------------------------------------------------------------
49 // constants
50 // ----------------------------------------------------------------------------
51
52 static const int wxID_TEXT = 3000;
53
54 // ---------------------------------------------------------------------------
55 // macros
56 // ---------------------------------------------------------------------------
57
58 /* Macro for avoiding #ifdefs when value have to be different depending on size of
59 device we display on - take it from something like wxDesktopPolicy in the future
60 */
61
62 #if defined(__SMARTPHONE__)
63 #define wxLARGESMALL(large,small) small
64 #else
65 #define wxLARGESMALL(large,small) large
66 #endif
67
68 // ============================================================================
69 // implementation
70 // ============================================================================
71
72 // ----------------------------------------------------------------------------
73 // wxTextEntryDialog
74 // ----------------------------------------------------------------------------
75
76 BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
77 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
78 END_EVENT_TABLE()
79
80 IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
81
82 wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
83 const wxString& message,
84 const wxString& caption,
85 const wxString& value,
86 long style,
87 const wxPoint& pos)
88 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
89 wxDEFAULT_DIALOG_STYLE),
90 m_value(value)
91 {
92 m_dialogStyle = style;
93 m_value = value;
94
95 wxBeginBusyCursor();
96
97 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
98
99 #if wxUSE_STATTEXT
100 // 1) text message
101 topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(10,0) );
102 #endif
103
104 // 2) text ctrl
105 m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
106 wxDefaultPosition, wxSize(300, wxDefaultCoord),
107 style & ~wxTextEntryDialogStyle);
108 topsizer->Add( m_textctrl, style & wxTE_MULTILINE ? 1 : 0, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(15,0) );
109
110 #if wxUSE_VALIDATORS
111 wxTextValidator validator( wxFILTER_NONE, &m_value );
112 m_textctrl->SetValidator( validator );
113 #endif // wxUSE_VALIDATORS
114
115 // 3) buttons if any
116 wxSizer *buttonSizer = CreateButtonSizer( style & ButtonSizerFlags , true, wxLARGESMALL(10,0) );
117 if(buttonSizer->GetChildren().GetCount() > 0 )
118 {
119 topsizer->Add( buttonSizer, 0, wxEXPAND | wxALL, wxLARGESMALL(10,0) );
120 }
121 else
122 {
123 topsizer->AddSpacer( wxLARGESMALL(15,0) );
124 delete buttonSizer;
125 }
126
127 SetAutoLayout( true );
128 SetSizer( topsizer );
129
130 topsizer->SetSizeHints( this );
131 topsizer->Fit( this );
132
133 if ( style & wxCENTRE )
134 Centre( wxBOTH );
135
136 m_textctrl->SetSelection(-1, -1);
137 m_textctrl->SetFocus();
138
139 wxEndBusyCursor();
140 }
141
142 void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
143 {
144 #if wxUSE_VALIDATORS
145 if( Validate() && TransferDataFromWindow() )
146 {
147 EndModal( wxID_OK );
148 }
149 #else
150 m_value = m_textctrl->GetValue();
151
152 EndModal(wxID_OK);
153 #endif
154 // wxUSE_VALIDATORS
155 }
156
157 void wxTextEntryDialog::SetValue(const wxString& val)
158 {
159 m_value = val;
160
161 m_textctrl->SetValue(val);
162 }
163
164 #if wxUSE_VALIDATORS
165 void wxTextEntryDialog::SetTextValidator( long style )
166 {
167 wxTextValidator validator( style, &m_value );
168 m_textctrl->SetValidator( validator );
169 }
170
171 void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator )
172 {
173 m_textctrl->SetValidator( validator );
174 }
175
176 #endif
177 // wxUSE_VALIDATORS
178
179 // ----------------------------------------------------------------------------
180 // wxPasswordEntryDialog
181 // ----------------------------------------------------------------------------
182
183 IMPLEMENT_CLASS(wxPasswordEntryDialog, wxTextEntryDialog)
184
185 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow *parent,
186 const wxString& message,
187 const wxString& caption,
188 const wxString& value,
189 long style,
190 const wxPoint& pos)
191 : wxTextEntryDialog(parent, message, caption, value,
192 style | wxTE_PASSWORD, pos)
193 {
194 // Only change from wxTextEntryDialog is the password style
195 }
196
197 #endif // wxUSE_TEXTDLG