]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/numdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
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
);
114 if (!prompt
.IsEmpty())
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
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
129 // smart phones does not support or do not waste space for wxButtons
130 #ifdef __SMARTPHONE__
132 SetRightMenu(wxID_CANCEL
, _("Cancel"));
134 #else // __SMARTPHONE__/!__SMARTPHONE__
138 topsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
142 topsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
| wxALL
, 10 );
144 #endif // !__SMARTPHONE__
146 SetSizer( topsizer
);
147 SetAutoLayout( true );
149 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
150 topsizer
->SetSizeHints( this );
151 topsizer
->Fit( this );
156 m_spinctrl
->SetSelection(-1, -1);
157 m_spinctrl
->SetFocus();
162 void wxNumberEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
165 wxString tmp
= m_spinctrl
->GetValue();
166 if ( wxSscanf(tmp
, _T("%ld"), &m_value
) != 1 )
167 EndModal(wxID_CANCEL
);
170 m_value
= m_spinctrl
->GetValue();
172 if ( m_value
< m_min
|| m_value
> m_max
)
174 // not a number or out of range
176 EndModal(wxID_CANCEL
);
182 void wxNumberEntryDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
184 EndModal(wxID_CANCEL
);
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 // wxGetTextFromUser is in utilscmn.cpp
193 long wxGetNumberFromUser(const wxString
& msg
,
194 const wxString
& prompt
,
195 const wxString
& title
,
202 wxNumberEntryDialog
dialog(parent
, msg
, prompt
, title
,
203 value
, min
, max
, pos
);
204 if (dialog
.ShowModal() == wxID_OK
)
205 return dialog
.GetValue();
210 #endif // wxUSE_NUMBERDLG