]> git.saurik.com Git - wxWidgets.git/blame - src/generic/textdlgg.cpp
Update copyright year in the version information resource.
[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
b8d6be7f 68bool wxTextEntryDialog::Create(wxWindow *parent,
c50f1fb9
VZ
69 const wxString& message,
70 const wxString& caption,
71 const wxString& value,
72 long style,
73 const wxPoint& pos)
c801d85f 74{
b8d6be7f
VZ
75 if ( !wxDialog::Create(GetParentForModalDialog(parent, style),
76 wxID_ANY, caption,
77 pos, wxDefaultSize,
97c15a53 78 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) )
b8d6be7f
VZ
79 {
80 return false;
81 }
82
92afa2b1
RR
83 m_dialogStyle = style;
84 m_value = value;
85
86 wxBeginBusyCursor();
479cd5de 87
92afa2b1
RR
88 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
89
bd9f3519
VZ
90 wxSizerFlags flagsBorder2;
91 flagsBorder2.DoubleBorder();
92
132422c4 93#if wxUSE_STATTEXT
92afa2b1 94 // 1) text message
bd9f3519 95 topsizer->Add(CreateTextSizer(message), flagsBorder2);
897b24cf 96#endif
479cd5de 97
92afa2b1 98 // 2) text ctrl
a294c6d5 99 m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
422d0ff0 100 wxDefaultPosition, wxSize(300, wxDefaultCoord),
a294c6d5 101 style & ~wxTextEntryDialogStyle);
bd9f3519
VZ
102
103 topsizer->Add(m_textctrl,
104 wxSizerFlags(style & wxTE_MULTILINE ? 1 : 0).
105 Expand().
106 TripleBorder(wxLEFT | wxRIGHT));
92afa2b1 107
897b24cf 108 // 3) buttons if any
12a124dd 109 wxSizer *buttonSizer = CreateSeparatedButtonSizer(style & (wxOK | wxCANCEL));
bd9f3519 110 if ( buttonSizer )
897b24cf 111 {
bd9f3519 112 topsizer->Add(buttonSizer, wxSizerFlags(flagsBorder2).Expand());
897b24cf 113 }
0d1f53ca 114
ca65c044 115 SetAutoLayout( true );
8b17ba72 116 SetSizer( topsizer );
479cd5de 117
92afa2b1
RR
118 topsizer->SetSizeHints( this );
119 topsizer->Fit( this );
92afa2b1 120
01e13147 121 if ( style & wxCENTRE )
13d13a9e 122 Centre( wxBOTH );
c801d85f 123
70680b61 124 m_textctrl->SelectAll();
c50f1fb9 125 m_textctrl->SetFocus();
92afa2b1
RR
126
127 wxEndBusyCursor();
b8d6be7f
VZ
128
129 return true;
c801d85f
KB
130}
131
42fe16e5
VZ
132bool wxTextEntryDialog::TransferDataToWindow()
133{
134 m_textctrl->SetValue(m_value);
135
136 return wxDialog::TransferDataToWindow();
137}
138
139bool wxTextEntryDialog::TransferDataFromWindow()
140{
141 m_value = m_textctrl->GetValue();
142
143 return wxDialog::TransferDataFromWindow();
144}
145
c801d85f
KB
146void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
147{
42fe16e5 148 if ( Validate() && TransferDataFromWindow() )
fc0d5b6b
JS
149 {
150 EndModal( wxID_OK );
151 }
c801d85f 152}
1e6feb95 153
62a58fbe
VZ
154void wxTextEntryDialog::SetMaxLength(unsigned long len)
155{
156 m_textctrl->SetMaxLength(len);
157}
158
a8f6ef51
VZ
159void wxTextEntryDialog::SetValue(const wxString& val)
160{
161 m_value = val;
162
163 m_textctrl->SetValue(val);
164}
165
fc0d5b6b 166#if wxUSE_VALIDATORS
40ae9600
FM
167
168#if WXWIN_COMPATIBILITY_2_8
fc0d5b6b 169void wxTextEntryDialog::SetTextValidator( long style )
40ae9600
FM
170{
171 SetTextValidator((wxTextValidatorStyle)style);
172}
173#endif
174
175void wxTextEntryDialog::SetTextValidator( wxTextValidatorStyle style )
fc0d5b6b 176{
42fe16e5 177 SetTextValidator(wxTextValidator(style));
fc0d5b6b
JS
178}
179
fbfb8bcc 180void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator )
fc0d5b6b
JS
181{
182 m_textctrl->SetValidator( validator );
183}
184
42fe16e5 185#endif // wxUSE_VALIDATORS
fc0d5b6b 186
e9f4948e
KH
187// ----------------------------------------------------------------------------
188// wxPasswordEntryDialog
189// ----------------------------------------------------------------------------
190
191IMPLEMENT_CLASS(wxPasswordEntryDialog, wxTextEntryDialog)
192
193wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow *parent,
194 const wxString& message,
195 const wxString& caption,
196 const wxString& value,
197 long style,
198 const wxPoint& pos)
199 : wxTextEntryDialog(parent, message, caption, value,
200 style | wxTE_PASSWORD, pos)
201{
202 // Only change from wxTextEntryDialog is the password style
203}
204
1e6feb95 205#endif // wxUSE_TEXTDLG