]>
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 // ----------------------------------------------------------------------------
66 // wxNumberEntryDialog
67 // ----------------------------------------------------------------------------
69 BEGIN_EVENT_TABLE(wxNumberEntryDialog
, wxDialog
)
70 EVT_BUTTON(wxID_OK
, wxNumberEntryDialog::OnOK
)
71 EVT_BUTTON(wxID_CANCEL
, wxNumberEntryDialog::OnCancel
)
74 IMPLEMENT_CLASS(wxNumberEntryDialog
, wxDialog
)
76 wxNumberEntryDialog::wxNumberEntryDialog(wxWindow
*parent
,
77 const wxString
& message
,
78 const wxString
& prompt
,
79 const wxString
& caption
,
84 : wxDialog(parent
, -1, caption
,
93 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
96 topsizer
->Add( CreateTextSizer( message
), 0, wxALL
, 10 );
98 // 2) prompt and text ctrl
99 wxBoxSizer
*inputsizer
= new wxBoxSizer( wxHORIZONTAL
);
101 if (!prompt
.IsEmpty())
102 inputsizer
->Add( new wxStaticText( this, -1, prompt
), 0, wxCENTER
| wxLEFT
, 10 );
105 valStr
.Printf(wxT("%ld"), m_value
);
106 m_spinctrl
= new wxSpinCtrl(this, -1, valStr
, wxDefaultPosition
, wxSize( 140, -1 ) );
108 m_spinctrl
->SetRange((int)m_min
, (int)m_max
);
110 inputsizer
->Add( m_spinctrl
, 1, wxCENTER
| wxLEFT
| wxRIGHT
, 10 );
112 topsizer
->Add( inputsizer
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
116 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
120 topsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTRE
| wxALL
, 10 );
122 SetSizer( topsizer
);
123 SetAutoLayout( TRUE
);
125 topsizer
->SetSizeHints( this );
126 topsizer
->Fit( this );
130 m_spinctrl
->SetSelection(-1, -1);
131 m_spinctrl
->SetFocus();
136 void wxNumberEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
139 wxString tmp
= m_spinctrl
->GetValue();
140 if ( wxSscanf(tmp
, _T("%ld"), &m_value
) != 1 )
141 EndModal(wxID_CANCEL
);
144 m_value
= m_spinctrl
->GetValue();
146 if ( m_value
< m_min
|| m_value
> m_max
)
148 // not a number or out of range
149 EndModal(wxID_CANCEL
);
155 void wxNumberEntryDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
157 EndModal(wxID_CANCEL
);
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 // wxGetTextFromUser is in utilscmn.cpp
166 long wxGetNumberFromUser(const wxString
& msg
,
167 const wxString
& prompt
,
168 const wxString
& title
,
175 wxNumberEntryDialog
dialog(parent
, msg
, prompt
, title
,
176 value
, min
, max
, pos
);
177 if (dialog
.ShowModal() == wxID_OK
)
178 return dialog
.GetValue();
183 #endif // wxUSE_NUMBERDLG