]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "numdlgg.cpp"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/dialog.h"
38 #include "wx/button.h"
39 #include "wx/stattext.h"
40 #include "wx/textctrl.h"
46 #include "wx/statline.h"
50 #include "wx/spinctrl.h"
53 // this is where wxGetNumberFromUser() is declared
54 #include "wx/numdlg.h"
57 // wxTextCtrl will do instead of wxSpinCtrl if we don't have it
58 #define wxSpinCtrl wxTextCtrl
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 /* Macro for avoiding #ifdefs when value have to be different depending on size of
66 device we display on - take it from something like wxDesktopPolicy in the future
69 #if defined(__SMARTPHONE__)
70 #define wxLARGESMALL(large,small) small
72 #define wxLARGESMALL(large,small) large
75 // ============================================================================
77 // ============================================================================
79 // ----------------------------------------------------------------------------
80 // wxNumberEntryDialog
81 // ----------------------------------------------------------------------------
83 BEGIN_EVENT_TABLE(wxNumberEntryDialog
, wxDialog
)
84 EVT_BUTTON(wxID_OK
, wxNumberEntryDialog::OnOK
)
85 EVT_BUTTON(wxID_CANCEL
, wxNumberEntryDialog::OnCancel
)
88 IMPLEMENT_CLASS(wxNumberEntryDialog
, wxDialog
)
90 wxNumberEntryDialog::wxNumberEntryDialog(wxWindow
*parent
,
91 const wxString
& message
,
92 const wxString
& prompt
,
93 const wxString
& caption
,
98 : wxDialog(parent
, wxID_ANY
, caption
,
107 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
110 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, 10 );
112 // 2) prompt and text ctrl
113 wxBoxSizer
*inputsizer
= new wxBoxSizer( wxHORIZONTAL
);
115 if (!prompt
.IsEmpty())
116 inputsizer
->Add( new wxStaticText( this, wxID_ANY
, prompt
), 0, wxCENTER
| wxLEFT
, 10 );
119 valStr
.Printf(wxT("%ld"), m_value
);
120 m_spinctrl
= new wxSpinCtrl(this, wxID_ANY
, valStr
, wxDefaultPosition
, wxSize( 140, wxDefaultCoord
) );
122 m_spinctrl
->SetRange((int)m_min
, (int)m_max
);
124 inputsizer
->Add( m_spinctrl
, 1, wxCENTER
| wxLEFT
| wxRIGHT
, 10 );
126 topsizer
->Add( inputsizer
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
128 // smart phones does not support or do not waste space for wxButtons
129 #ifdef __SMARTPHONE__
131 SetRightMenu(wxID_CANCEL
, _("Cancel"));
133 #else // __SMARTPHONE__/!__SMARTPHONE__
137 topsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
141 topsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
| wxALL
, 10 );
143 #endif // !__SMARTPHONE__
145 SetSizer( topsizer
);
146 SetAutoLayout( true );
148 topsizer
->SetSizeHints( this );
149 topsizer
->Fit( this );
153 m_spinctrl
->SetSelection(-1, -1);
154 m_spinctrl
->SetFocus();
159 void wxNumberEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
162 wxString tmp
= m_spinctrl
->GetValue();
163 if ( wxSscanf(tmp
, _T("%ld"), &m_value
) != 1 )
164 EndModal(wxID_CANCEL
);
167 m_value
= m_spinctrl
->GetValue();
169 if ( m_value
< m_min
|| m_value
> m_max
)
171 // not a number or out of range
173 EndModal(wxID_CANCEL
);
179 void wxNumberEntryDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
181 EndModal(wxID_CANCEL
);
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 // wxGetTextFromUser is in utilscmn.cpp
190 long wxGetNumberFromUser(const wxString
& msg
,
191 const wxString
& prompt
,
192 const wxString
& title
,
199 wxNumberEntryDialog
dialog(parent
, msg
, prompt
, title
,
200 value
, min
, max
, pos
);
201 if (dialog
.ShowModal() == wxID_OK
)
202 return dialog
.GetValue();
207 #endif // wxUSE_NUMBERDLG