]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/numdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/numdlgg.cpp
3 // Purpose: wxGetNumberFromUser implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.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"
46 #include "wx/spinctrl.h"
49 // this is where wxGetNumberFromUser() is declared
50 #include "wx/numdlg.h"
53 // wxTextCtrl will do instead of wxSpinCtrl if we don't have it
54 #define wxSpinCtrl wxTextCtrl
57 // ---------------------------------------------------------------------------
59 // ---------------------------------------------------------------------------
61 /* Macro for avoiding #ifdefs when value have to be different depending on size of
62 device we display on - take it from something like wxDesktopPolicy in the future
65 #if defined(__SMARTPHONE__)
66 #define wxLARGESMALL(large,small) small
68 #define wxLARGESMALL(large,small) large
71 // ============================================================================
73 // ============================================================================
75 // ----------------------------------------------------------------------------
76 // wxNumberEntryDialog
77 // ----------------------------------------------------------------------------
79 BEGIN_EVENT_TABLE(wxNumberEntryDialog
, wxDialog
)
80 EVT_BUTTON(wxID_OK
, wxNumberEntryDialog::OnOK
)
81 EVT_BUTTON(wxID_CANCEL
, wxNumberEntryDialog::OnCancel
)
84 IMPLEMENT_CLASS(wxNumberEntryDialog
, wxDialog
)
86 wxNumberEntryDialog::wxNumberEntryDialog(wxWindow
*parent
,
87 const wxString
& message
,
88 const wxString
& prompt
,
89 const wxString
& caption
,
94 : wxDialog(parent
, wxID_ANY
, caption
,
103 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
106 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, 10 );
109 // 2) prompt and text ctrl
110 wxBoxSizer
*inputsizer
= new wxBoxSizer( wxHORIZONTAL
);
115 inputsizer
->Add( new wxStaticText( this, wxID_ANY
, prompt
), 0, wxCENTER
| wxLEFT
, 10 );
120 valStr
.Printf(wxT("%ld"), m_value
);
121 m_spinctrl
= new wxSpinCtrl(this, wxID_ANY
, valStr
, wxDefaultPosition
, wxSize( 140, wxDefaultCoord
) );
123 m_spinctrl
->SetRange((int)m_min
, (int)m_max
);
125 inputsizer
->Add( m_spinctrl
, 1, wxCENTER
| wxLEFT
| wxRIGHT
, 10 );
127 topsizer
->Add( inputsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
130 wxSizer
*buttonSizer
= CreateButtonSizer( wxOK
|wxCANCEL
, true, wxLARGESMALL(10,0) );
131 if(buttonSizer
->GetChildren().GetCount() > 0 )
133 topsizer
->Add( buttonSizer
, 0, wxEXPAND
| wxALL
, wxLARGESMALL(10,0) );
137 topsizer
->AddSpacer( wxLARGESMALL(15,0) );
141 SetSizer( topsizer
);
142 SetAutoLayout( true );
144 topsizer
->SetSizeHints( this );
145 topsizer
->Fit( this );
149 m_spinctrl
->SetSelection(-1, -1);
150 m_spinctrl
->SetFocus();
155 void wxNumberEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
158 wxString tmp
= m_spinctrl
->GetValue();
159 if ( wxSscanf(tmp
, _T("%ld"), &m_value
) != 1 )
160 EndModal(wxID_CANCEL
);
163 m_value
= m_spinctrl
->GetValue();
165 if ( m_value
< m_min
|| m_value
> m_max
)
167 // not a number or out of range
169 EndModal(wxID_CANCEL
);
175 void wxNumberEntryDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
177 EndModal(wxID_CANCEL
);
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 // wxGetTextFromUser is in utilscmn.cpp
186 long wxGetNumberFromUser(const wxString
& msg
,
187 const wxString
& prompt
,
188 const wxString
& title
,
195 wxNumberEntryDialog
dialog(parent
, msg
, prompt
, title
,
196 value
, min
, max
, pos
);
197 if (dialog
.ShowModal() == wxID_OK
)
198 return dialog
.GetValue();
203 #endif // wxUSE_NUMBERDLG