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