]> git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
Correct Mac OX/iPhone check in libpng.
[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 char wxGetTextFromUserPromptStr[] = "Input Text";
46 const char wxGetPasswordFromUserPromptStr[] = "Enter Password";
47
48 // ----------------------------------------------------------------------------
49 // constants
50 // ----------------------------------------------------------------------------
51
52 static const int wxID_TEXT = 3000;
53
54 // ============================================================================
55 // implementation
56 // ============================================================================
57
58 // ----------------------------------------------------------------------------
59 // wxTextEntryDialog
60 // ----------------------------------------------------------------------------
61
62 BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
63 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
64 END_EVENT_TABLE()
65
66 IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
67
68 wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
69 const wxString& message,
70 const wxString& caption,
71 const wxString& value,
72 long style,
73 const wxPoint& pos)
74 : wxDialog(GetParentForModalDialog(parent, style),
75 wxID_ANY, caption, pos, wxDefaultSize,
76 wxDEFAULT_DIALOG_STYLE),
77 m_value(value)
78 {
79 m_dialogStyle = style;
80 m_value = value;
81
82 wxBeginBusyCursor();
83
84 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
85
86 wxSizerFlags flagsBorder2;
87 flagsBorder2.DoubleBorder();
88
89 #if wxUSE_STATTEXT
90 // 1) text message
91 topsizer->Add(CreateTextSizer(message), flagsBorder2);
92 #endif
93
94 // 2) text ctrl
95 m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
96 wxDefaultPosition, wxSize(300, wxDefaultCoord),
97 style & ~wxTextEntryDialogStyle);
98
99 topsizer->Add(m_textctrl,
100 wxSizerFlags(style & wxTE_MULTILINE ? 1 : 0).
101 Expand().
102 TripleBorder(wxLEFT | wxRIGHT));
103
104 #if wxUSE_VALIDATORS
105 wxTextValidator validator( wxFILTER_NONE, &m_value );
106 m_textctrl->SetValidator( validator );
107 #endif // wxUSE_VALIDATORS
108
109 // 3) buttons if any
110 wxSizer *buttonSizer = CreateSeparatedButtonSizer(style & (wxOK | wxCANCEL));
111 if ( buttonSizer )
112 {
113 topsizer->Add(buttonSizer, wxSizerFlags(flagsBorder2).Expand());
114 }
115
116 SetAutoLayout( true );
117 SetSizer( topsizer );
118
119 topsizer->SetSizeHints( this );
120 topsizer->Fit( this );
121
122 if ( style & wxCENTRE )
123 Centre( wxBOTH );
124
125 m_textctrl->SetSelection(-1, -1);
126 m_textctrl->SetFocus();
127
128 wxEndBusyCursor();
129 }
130
131 void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
132 {
133 #if wxUSE_VALIDATORS
134 if( Validate() && TransferDataFromWindow() )
135 {
136 EndModal( wxID_OK );
137 }
138 #else
139 m_value = m_textctrl->GetValue();
140
141 EndModal(wxID_OK);
142 #endif
143 // wxUSE_VALIDATORS
144 }
145
146 void wxTextEntryDialog::SetValue(const wxString& val)
147 {
148 m_value = val;
149
150 m_textctrl->SetValue(val);
151 }
152
153 #if wxUSE_VALIDATORS
154
155 #if WXWIN_COMPATIBILITY_2_8
156 void wxTextEntryDialog::SetTextValidator( long style )
157 {
158 SetTextValidator((wxTextValidatorStyle)style);
159 }
160 #endif
161
162 void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style )
163 {
164 wxTextValidator validator( style, &m_value );
165 m_textctrl->SetValidator( validator );
166 }
167
168 void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator )
169 {
170 m_textctrl->SetValidator( validator );
171 }
172
173 #endif
174 // wxUSE_VALIDATORS
175
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
194 #endif // wxUSE_TEXTDLG