]>
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
| 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
);
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 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
128 topsizer
->SetSizeHints( this );
129 topsizer
->Fit( this );
131 if ( style
& wxCENTRE
)
135 m_textctrl
->SetSelection(-1, -1);
136 m_textctrl
->SetFocus();
141 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
144 if( Validate() && TransferDataFromWindow() )
149 m_value
= m_textctrl
->GetValue();
156 void wxTextEntryDialog::SetValue(const wxString
& val
)
160 m_textctrl
->SetValue(val
);
164 void wxTextEntryDialog::SetTextValidator( long style
)
166 wxTextValidator
validator( style
, &m_value
);
167 m_textctrl
->SetValidator( validator
);
170 void wxTextEntryDialog::SetTextValidator( const wxTextValidator
& validator
)
172 m_textctrl
->SetValidator( validator
);
178 // ----------------------------------------------------------------------------
179 // wxPasswordEntryDialog
180 // ----------------------------------------------------------------------------
182 IMPLEMENT_CLASS(wxPasswordEntryDialog
, wxTextEntryDialog
)
184 wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow
*parent
,
185 const wxString
& message
,
186 const wxString
& caption
,
187 const wxString
& value
,
190 : wxTextEntryDialog(parent
, message
, caption
, value
,
191 style
| wxTE_PASSWORD
, pos
)
193 // Only change from wxTextEntryDialog is the password style
196 #endif // wxUSE_TEXTDLG