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