]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/textdlgg.cpp
added InitCommandEventWithItems() and call it from wxChoice and wxComboBox code to...
[wxWidgets.git] / src / generic / textdlgg.cpp
... / ...
CommitLineData
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#ifndef WX_PRECOMP
30 #include "wx/utils.h"
31 #include "wx/dialog.h"
32 #include "wx/button.h"
33 #include "wx/stattext.h"
34 #include "wx/textctrl.h"
35 #include "wx/intl.h"
36 #include "wx/sizer.h"
37#endif
38
39#if wxUSE_STATLINE
40 #include "wx/statline.h"
41#endif
42
43#include "wx/generic/textdlgg.h"
44
45// ----------------------------------------------------------------------------
46// constants
47// ----------------------------------------------------------------------------
48
49static const int wxID_TEXT = 3000;
50
51// ---------------------------------------------------------------------------
52// macros
53// ---------------------------------------------------------------------------
54
55/* Macro for avoiding #ifdefs when value have to be different depending on size of
56 device we display on - take it from something like wxDesktopPolicy in the future
57 */
58
59#if defined(__SMARTPHONE__)
60 #define wxLARGESMALL(large,small) small
61#else
62 #define wxLARGESMALL(large,small) large
63#endif
64
65// ============================================================================
66// implementation
67// ============================================================================
68
69// ----------------------------------------------------------------------------
70// wxTextEntryDialog
71// ----------------------------------------------------------------------------
72
73BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
74 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
75END_EVENT_TABLE()
76
77IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
78
79wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
80 const wxString& message,
81 const wxString& caption,
82 const wxString& value,
83 long style,
84 const wxPoint& pos)
85 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
86 wxDEFAULT_DIALOG_STYLE),
87 m_value(value)
88{
89 m_dialogStyle = style;
90 m_value = value;
91
92 wxBeginBusyCursor();
93
94 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
95
96#if wxUSE_STATTEXT
97 // 1) text message
98 topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(10,0) );
99#endif
100
101 // 2) text ctrl
102 m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
103 wxDefaultPosition, wxSize(300, wxDefaultCoord),
104 style & ~wxTextEntryDialogStyle);
105 topsizer->Add( m_textctrl, style & wxTE_MULTILINE ? 1 : 0, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(15,0) );
106
107#if wxUSE_VALIDATORS
108 wxTextValidator validator( wxFILTER_NONE, &m_value );
109 m_textctrl->SetValidator( validator );
110#endif // wxUSE_VALIDATORS
111
112 // 3) buttons if any
113 wxSizer *buttonSizer = CreateButtonSizer( style & ButtonSizerFlags , true, wxLARGESMALL(10,0) );
114 if(buttonSizer->GetChildren().GetCount() > 0 )
115 {
116 topsizer->Add( buttonSizer, 0, wxEXPAND | wxALL, wxLARGESMALL(10,0) );
117 }
118 else
119 {
120 topsizer->AddSpacer( wxLARGESMALL(15,0) );
121 delete buttonSizer;
122 }
123
124 SetAutoLayout( true );
125 SetSizer( topsizer );
126
127 topsizer->SetSizeHints( this );
128 topsizer->Fit( this );
129
130 if ( style & wxCENTRE )
131 Centre( wxBOTH );
132
133 m_textctrl->SetSelection(-1, -1);
134 m_textctrl->SetFocus();
135
136 wxEndBusyCursor();
137}
138
139void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
140{
141#if wxUSE_VALIDATORS
142 if( Validate() && TransferDataFromWindow() )
143 {
144 EndModal( wxID_OK );
145 }
146#else
147 m_value = m_textctrl->GetValue();
148
149 EndModal(wxID_OK);
150#endif
151 // wxUSE_VALIDATORS
152}
153
154void wxTextEntryDialog::SetValue(const wxString& val)
155{
156 m_value = val;
157
158 m_textctrl->SetValue(val);
159}
160
161#if wxUSE_VALIDATORS
162void wxTextEntryDialog::SetTextValidator( long style )
163{
164 wxTextValidator validator( style, &m_value );
165 m_textctrl->SetValidator( validator );
166}
167
168void wxTextEntryDialog::SetTextValidator( const wxTextValidator& validator )
169{
170 m_textctrl->SetValidator( validator );
171}
172
173#endif
174 // wxUSE_VALIDATORS
175
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
194#endif // wxUSE_TEXTDLG