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