]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
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"
31 #include "wx/dialog.h"
32 #include "wx/button.h"
33 #include "wx/stattext.h"
34 #include "wx/textctrl.h"
40 #include "wx/statline.h"
43 #include "wx/generic/textdlgg.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 static const int wxID_TEXT
= 3000;
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
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
59 #if defined(__SMARTPHONE__)
60 #define wxLARGESMALL(large,small) small
62 #define wxLARGESMALL(large,small) large
65 // ============================================================================
67 // ============================================================================
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
74 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
77 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
79 wxTextEntryDialog::wxTextEntryDialog(wxWindow
*parent
,
80 const wxString
& message
,
81 const wxString
& caption
,
82 const wxString
& value
,
85 : wxDialog(parent
, wxID_ANY
, caption
, pos
, wxDefaultSize
,
86 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
),
89 m_dialogStyle
= style
;
94 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
98 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, wxLARGESMALL(10,0) );
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) );
108 wxTextValidator
validator( wxFILTER_NONE
, &m_value
);
109 m_textctrl
->SetValidator( validator
);
113 // smart phones does not support or do not waste space for wxButtons
114 #ifdef __SMARTPHONE__
116 SetRightMenu(wxID_CANCEL
, _("Cancel"));
118 #else // __SMARTPHONE__/!__SMARTPHONE__
122 topsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
126 topsizer
->Add( CreateButtonSizer( style
), 0, wxEXPAND
| wxALL
, 10 );
128 #endif // !__SMARTPHONE__
130 SetAutoLayout( true );
131 SetSizer( topsizer
);
133 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
134 topsizer
->SetSizeHints( this );
135 topsizer
->Fit( this );
137 if ( style
& wxCENTRE
)
141 m_textctrl
->SetSelection(-1, -1);
142 m_textctrl
->SetFocus();
147 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
150 if( Validate() && TransferDataFromWindow() )
155 m_value
= m_textctrl
->GetValue();
162 void wxTextEntryDialog::SetValue(const wxString
& val
)
166 m_textctrl
->SetValue(val
);
170 void wxTextEntryDialog::SetTextValidator( long style
)
172 wxTextValidator
validator( style
, &m_value
);
173 m_textctrl
->SetValidator( validator
);
176 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
178 m_textctrl
->SetValidator( validator
);
184 // ----------------------------------------------------------------------------
185 // wxPasswordEntryDialog
186 // ----------------------------------------------------------------------------
188 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
190 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
191 const wxString
& message
,
192 const wxString
& caption
,
193 const wxString
& value
,
196 : wxTextEntryDialog(parent
, message
, caption
, value
,
197 style
| wxTE_PASSWORD
, pos
)
199 // Only change from wxTextEntryDialog is the password style
202 #endif // wxUSE_TEXTDLG