]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "textdlgg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/dialog.h"
36 #include "wx/button.h"
37 #include "wx/stattext.h"
38 #include "wx/textctrl.h"
44 #include "wx/statline.h"
47 #include "wx/generic/textdlgg.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 static const int wxID_TEXT
= 3000;
55 // ---------------------------------------------------------------------------
57 // ---------------------------------------------------------------------------
59 /* Macro for avoiding #ifdefs when value have to be different depending on size of
60 device we display on - take it from something like wxDesktopPolicy in the future
63 #if defined(__SMARTPHONE__)
64 #define wxLARGESMALL(large,small) small
66 #define wxLARGESMALL(large,small) large
69 // ============================================================================
71 // ============================================================================
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
78 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
81 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
83 wxTextEntryDialog::wxTextEntryDialog(wxWindow
*parent
,
84 const wxString
& message
,
85 const wxString
& caption
,
86 const wxString
& value
,
89 : wxDialog(parent
, wxID_ANY
, caption
, pos
, wxDefaultSize
,
90 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
),
93 m_dialogStyle
= style
;
98 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
102 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, wxLARGESMALL(10,0) );
106 m_textctrl
= new wxTextCtrl(this, wxID_TEXT
, value
,
107 wxDefaultPosition
, wxSize(300, wxDefaultCoord
),
108 style
& ~wxTextEntryDialogStyle
);
109 topsizer
->Add( m_textctrl
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, wxLARGESMALL(15,0) );
112 wxTextValidator
validator( wxFILTER_NONE
, &m_value
);
113 m_textctrl
->SetValidator( validator
);
117 // smart phones does not support or do not waste space for wxButtons
118 #ifdef __SMARTPHONE__
120 SetRightMenu(wxID_CANCEL
, _("Cancel"));
122 #else // __SMARTPHONE__/!__SMARTPHONE__
126 topsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
130 topsizer
->Add( CreateButtonSizer( style
), 0, wxEXPAND
| wxALL
, 10 );
132 #endif // !__SMARTPHONE__
134 SetAutoLayout( true );
135 SetSizer( topsizer
);
137 topsizer
->SetSizeHints( this );
138 topsizer
->Fit( this );
140 if ( style
& wxCENTRE
)
143 m_textctrl
->SetSelection(-1, -1);
144 m_textctrl
->SetFocus();
149 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
152 if( Validate() && TransferDataFromWindow() )
157 m_value
= m_textctrl
->GetValue();
164 void wxTextEntryDialog::SetValue(const wxString
& val
)
168 m_textctrl
->SetValue(val
);
172 void wxTextEntryDialog::SetTextValidator( long style
)
174 wxTextValidator
validator( style
, &m_value
);
175 m_textctrl
->SetValidator( validator
);
178 void wxTextEntryDialog::SetTextValidator( wxTextValidator
& validator
)
180 m_textctrl
->SetValidator( validator
);
186 // ----------------------------------------------------------------------------
187 // wxPasswordEntryDialog
188 // ----------------------------------------------------------------------------
190 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
192 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
193 const wxString
& message
,
194 const wxString
& caption
,
195 const wxString
& value
,
198 : wxTextEntryDialog(parent
, message
, caption
, value
,
199 style
| wxTE_PASSWORD
, pos
)
201 // Only change from wxTextEntryDialog is the password style
204 #endif // wxUSE_TEXTDLG