1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/textdlgg.cpp
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/generic/textdlgg.h"
33 #include "wx/dialog.h"
34 #include "wx/button.h"
35 #include "wx/stattext.h"
36 #include "wx/textctrl.h"
42 #include "wx/statline.h"
45 const wxChar wxGetTextFromUserPromptStr
[] = wxT("Input Text");
46 const wxChar wxGetPasswordFromUserPromptStr
[] = wxT("Enter Password");
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 static const int wxID_TEXT
= 3000;
54 // ---------------------------------------------------------------------------
56 // ---------------------------------------------------------------------------
58 /* Macro for avoiding #ifdefs when value have to be different depending on size of
59 device we display on - take it from something like wxDesktopPolicy in the future
62 #if defined(__SMARTPHONE__)
63 #define wxLARGESMALL(large,small) small
65 #define wxLARGESMALL(large,small) large
68 // ============================================================================
70 // ============================================================================
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
77 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
80 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
82 wxTextEntryDialog::wxTextEntryDialog(wxWindow
*parent
,
83 const wxString
& message
,
84 const wxString
& caption
,
85 const wxString
& value
,
88 : wxDialog(parent
, wxID_ANY
, caption
, pos
, wxDefaultSize
,
89 wxDEFAULT_DIALOG_STYLE
),
92 m_dialogStyle
= style
;
97 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
101 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, wxLARGESMALL(10,0) );
105 m_textctrl
= new wxTextCtrl(this, wxID_TEXT
, value
,
106 wxDefaultPosition
, wxSize(300, wxDefaultCoord
),
107 style
& ~wxTextEntryDialogStyle
);
108 topsizer
->Add( m_textctrl
, style
& wxTE_MULTILINE
? 1 : 0, wxEXPAND
| wxLEFT
|wxRIGHT
, wxLARGESMALL(15,0) );
111 wxTextValidator
validator( wxFILTER_NONE
, &m_value
);
112 m_textctrl
->SetValidator( validator
);
113 #endif // wxUSE_VALIDATORS
116 wxSizer
*buttonSizer
= CreateButtonSizer( style
& ButtonSizerFlags
, true, wxLARGESMALL(10,0) );
117 if(buttonSizer
->GetChildren().GetCount() > 0 )
119 topsizer
->Add( buttonSizer
, 0, wxEXPAND
| wxALL
, wxLARGESMALL(10,0) );
123 topsizer
->AddSpacer( wxLARGESMALL(15,0) );
127 SetAutoLayout( true );
128 SetSizer( topsizer
);
130 topsizer
->SetSizeHints( this );
131 topsizer
->Fit( this );
133 if ( style
& wxCENTRE
)
136 m_textctrl
->SetSelection(-1, -1);
137 m_textctrl
->SetFocus();
142 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
145 if( Validate() && TransferDataFromWindow() )
150 m_value
= m_textctrl
->GetValue();
157 void wxTextEntryDialog::SetValue(const wxString
& val
)
161 m_textctrl
->SetValue(val
);
165 void wxTextEntryDialog::SetTextValidator( long style
)
167 wxTextValidator
validator( style
, &m_value
);
168 m_textctrl
->SetValidator( validator
);
171 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
173 m_textctrl
->SetValidator( validator
);
179 // ----------------------------------------------------------------------------
180 // wxPasswordEntryDialog
181 // ----------------------------------------------------------------------------
183 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
185 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
186 const wxString
& message
,
187 const wxString
& caption
,
188 const wxString
& value
,
191 : wxTextEntryDialog(parent
, message
, caption
, value
,
192 style
| wxTE_PASSWORD
, pos
)
194 // Only change from wxTextEntryDialog is the password style
197 #endif // wxUSE_TEXTDLG