]>
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 // ----------------------------------------------------------------------------
62 // wxNumberEntryDialog
63 // ----------------------------------------------------------------------------
65 BEGIN_EVENT_TABLE(wxNumberEntryDialog
, wxDialog
)
66 EVT_BUTTON(wxID_OK
, wxNumberEntryDialog::OnOK
)
67 EVT_BUTTON(wxID_CANCEL
, wxNumberEntryDialog::OnCancel
)
70 IMPLEMENT_CLASS(wxNumberEntryDialog
, wxDialog
)
72 wxNumberEntryDialog::wxNumberEntryDialog(wxWindow
*parent
,
73 const wxString
& message
,
74 const wxString
& prompt
,
75 const wxString
& caption
,
80 : wxDialog(GetParentForModalDialog(parent
),
90 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
93 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, 10 );
96 // 2) prompt and text ctrl
97 wxBoxSizer
*inputsizer
= new wxBoxSizer( wxHORIZONTAL
);
102 inputsizer
->Add( new wxStaticText( this, wxID_ANY
, prompt
), 0, wxCENTER
| wxLEFT
, 10 );
107 valStr
.Printf(wxT("%ld"), m_value
);
108 m_spinctrl
= new wxSpinCtrl(this, wxID_ANY
, valStr
, wxDefaultPosition
, wxSize( 140, wxDefaultCoord
), wxSP_ARROW_KEYS
, (int)m_min
, (int)m_max
, (int)m_value
);
109 inputsizer
->Add( m_spinctrl
, 1, wxCENTER
| wxLEFT
| wxRIGHT
, 10 );
111 topsizer
->Add( inputsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
114 wxSizer
*buttonSizer
= CreateSeparatedButtonSizer(wxOK
| wxCANCEL
);
117 topsizer
->Add(buttonSizer
, wxSizerFlags().Expand().DoubleBorder());
120 SetSizer( topsizer
);
121 SetAutoLayout( true );
123 topsizer
->SetSizeHints( this );
124 topsizer
->Fit( this );
128 m_spinctrl
->SetSelection(-1, -1);
129 m_spinctrl
->SetFocus();
134 void wxNumberEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
137 wxString tmp
= m_spinctrl
->GetValue();
138 if ( wxSscanf(tmp
, _T("%ld"), &m_value
) != 1 )
139 EndModal(wxID_CANCEL
);
142 m_value
= m_spinctrl
->GetValue();
144 if ( m_value
< m_min
|| m_value
> m_max
)
146 // not a number or out of range
148 EndModal(wxID_CANCEL
);
154 void wxNumberEntryDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
156 EndModal(wxID_CANCEL
);
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 // wxGetTextFromUser is in utilscmn.cpp
165 long wxGetNumberFromUser(const wxString
& msg
,
166 const wxString
& prompt
,
167 const wxString
& title
,
174 wxNumberEntryDialog
dialog(parent
, msg
, prompt
, title
,
175 value
, min
, max
, pos
);
176 if (dialog
.ShowModal() == wxID_OK
)
177 return dialog
.GetValue();
182 #endif // wxUSE_NUMBERDLG