]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
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"
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
),
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
);
110 #endif // wxUSE_VALIDATORS
113 wxSizer
*buttonSizer
= CreateButtonSizer( style
& ButtonSizerFlags
, true, wxLARGESMALL(10,0) );
114 if(buttonSizer
->GetChildren().GetCount() > 0 )
116 topsizer
->Add( buttonSizer
, 0, wxEXPAND
| wxALL
, wxLARGESMALL(10,0) );
120 topsizer
->AddSpacer( wxLARGESMALL(15,0) );
124 SetAutoLayout( true );
125 SetSizer( topsizer
);
127 topsizer
->SetSizeHints( this );
128 topsizer
->Fit( this );
130 if ( style
& wxCENTRE
)
133 m_textctrl
->SetSelection(-1, -1);
134 m_textctrl
->SetFocus();
139 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
142 if( Validate() && TransferDataFromWindow() )
147 m_value
= m_textctrl
->GetValue();
154 void wxTextEntryDialog::SetValue(const wxString
& val
)
158 m_textctrl
->SetValue(val
);
162 void wxTextEntryDialog::SetTextValidator( long style
)
164 wxTextValidator
validator( style
, &m_value
);
165 m_textctrl
->SetValidator( validator
);
168 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
170 m_textctrl
->SetValidator( validator
);
176 // ----------------------------------------------------------------------------
177 // wxPasswordEntryDialog
178 // ----------------------------------------------------------------------------
180 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
182 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
183 const wxString
& message
,
184 const wxString
& caption
,
185 const wxString
& value
,
188 : wxTextEntryDialog(parent
, message
, caption
, value
,
189 style
| wxTE_PASSWORD
, pos
)
191 // Only change from wxTextEntryDialog is the password style
194 #endif // wxUSE_TEXTDLG