]>
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
7 // Copyright: (c) Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
32 #include "wx/dialog.h"
33 #include "wx/button.h"
34 #include "wx/stattext.h"
35 #include "wx/textctrl.h"
41 #include "wx/statline.h"
45 #include "wx/spinctrl.h"
48 // this is where wxGetNumberFromUser() is declared
49 #include "wx/numdlg.h"
52 // wxTextCtrl will do instead of wxSpinCtrl if we don't have it
53 #define wxSpinCtrl wxTextCtrl
56 // ============================================================================
58 // ============================================================================
60 // ----------------------------------------------------------------------------
61 // wxNumberEntryDialog
62 // ----------------------------------------------------------------------------
64 BEGIN_EVENT_TABLE(wxNumberEntryDialog
, wxDialog
)
65 EVT_BUTTON(wxID_OK
, wxNumberEntryDialog::OnOK
)
66 EVT_BUTTON(wxID_CANCEL
, wxNumberEntryDialog::OnCancel
)
69 IMPLEMENT_CLASS(wxNumberEntryDialog
, wxDialog
)
71 wxNumberEntryDialog::wxNumberEntryDialog(wxWindow
*parent
,
72 const wxString
& message
,
73 const wxString
& prompt
,
74 const wxString
& caption
,
79 : wxDialog(GetParentForModalDialog(parent
, 0),
89 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
92 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, 10 );
95 // 2) prompt and text ctrl
96 wxBoxSizer
*inputsizer
= new wxBoxSizer( wxHORIZONTAL
);
101 inputsizer
->Add( new wxStaticText( this, wxID_ANY
, prompt
), 0, wxCENTER
| wxLEFT
, 10 );
106 valStr
.Printf(wxT("%ld"), m_value
);
107 m_spinctrl
= new wxSpinCtrl(this, wxID_ANY
, valStr
, wxDefaultPosition
, wxSize( 140, wxDefaultCoord
), wxSP_ARROW_KEYS
, (int)m_min
, (int)m_max
, (int)m_value
);
108 inputsizer
->Add( m_spinctrl
, 1, wxCENTER
| wxLEFT
| wxRIGHT
, 10 );
110 topsizer
->Add( inputsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
113 wxSizer
*buttonSizer
= CreateSeparatedButtonSizer(wxOK
| wxCANCEL
);
116 topsizer
->Add(buttonSizer
, wxSizerFlags().Expand().DoubleBorder());
119 SetSizer( topsizer
);
120 SetAutoLayout( true );
122 topsizer
->SetSizeHints( this );
123 topsizer
->Fit( this );
127 m_spinctrl
->SetSelection(-1, -1);
128 m_spinctrl
->SetFocus();
133 void wxNumberEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
136 wxString tmp
= m_spinctrl
->GetValue();
137 if ( wxSscanf(tmp
, wxT("%ld"), &m_value
) != 1 )
138 EndModal(wxID_CANCEL
);
141 m_value
= m_spinctrl
->GetValue();
143 if ( m_value
< m_min
|| m_value
> m_max
)
145 // not a number or out of range
147 EndModal(wxID_CANCEL
);
153 void wxNumberEntryDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
155 EndModal(wxID_CANCEL
);
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 // wxGetTextFromUser is in utilscmn.cpp
164 long wxGetNumberFromUser(const wxString
& msg
,
165 const wxString
& prompt
,
166 const wxString
& title
,
173 wxNumberEntryDialog
dialog(parent
, msg
, prompt
, title
,
174 value
, min
, max
, pos
);
175 if (dialog
.ShowModal() == wxID_OK
)
176 return dialog
.GetValue();
181 #endif // wxUSE_NUMBERDLG